Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Sync form submissions tracking goal (#5545)
Artur Pata3c6db4efebaf
diff --git a/lib/plausible/goals/goals.ex b/lib/plausible/goals/goals.exindex fc137cafcf..06c84dd8cf 100644--- a/lib/plausible/goals/goals.ex+++ b/lib/plausible/goals/goals.ex@@ -258,6 +258,12 @@ defmodule Plausible.Goals do:okend+ @spec create_form_submissions(Plausible.Site.t()) :: :ok+ def create_form_submissions(%Plausible.Site{} = site) do+ create(site, %{"event_name" => "Form: Submission"}, upsert?: true)+ :ok+ end+@spec create_404(Plausible.Site.t()) :: :okdef create_404(%Plausible.Site{} = site) docreate(site, %{"event_name" => "404"}, upsert?: true)@@ -297,6 +303,17 @@ defmodule Plausible.Goals do:okend+ @spec delete_form_submissions(Plausible.Site.t()) :: :ok+ def delete_form_submissions(%Plausible.Site{} = site) do+ q =+ from g in Goal,+ where: g.site_id == ^site.id,+ where: g.event_name == "Form: Submission"++ Repo.delete_all(q)+ :ok+ end+defp insert_goal(site, params, upsert?) doparams = Map.delete(params, "site_id")diff --git a/lib/plausible_web/tracker.ex b/lib/plausible_web/tracker.exindex b3bba8de73..9e28e080b4 100644--- a/lib/plausible_web/tracker.ex+++ b/lib/plausible_web/tracker.ex@@ -96,7 +96,7 @@ defmodule PlausibleWeb.Tracker do# Sync plausible goals with the updated script configdefp sync_goals(site, original_config, updated_config) do- [:track_404_pages, :outbound_links, :file_downloads]+ [:track_404_pages, :outbound_links, :file_downloads, :form_submissions]|> Enum.map(fn key ->{key, Map.get(original_config, key, false), Map.get(updated_config, key, false)}end)@@ -107,6 +107,8 @@ defmodule PlausibleWeb.Tracker do{:outbound_links, true, false} -> Plausible.Goals.delete_outbound_links(site){:file_downloads, false, true} -> Plausible.Goals.create_file_downloads(site){:file_downloads, true, false} -> Plausible.Goals.delete_file_downloads(site)+ {:form_submissions, false, true} -> Plausible.Goals.create_form_submissions(site)+ {:form_submissions, true, false} -> Plausible.Goals.delete_form_submissions(site)_ -> nilend)end