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
Add backlinks between CRM, dashboard and site members (#4252)
Adrian Gruntkowski766807e9fd9d
diff --git a/lib/plausible/crm_extensions.ex b/lib/plausible/crm_extensions.exindex c4d082b668..9b09de3234 100644--- a/lib/plausible/crm_extensions.ex+++ b/lib/plausible/crm_extensions.ex@@ -25,6 +25,26 @@ defmodule Plausible.CrmExtensions do]end+ def javascripts(%{assigns: %{context: "sites", resource: "site", entry: %{domain: domain}}}) do+ base_url = PlausibleWeb.Endpoint.url()++ [+ Phoenix.HTML.raw("""+ <script type="text/javascript">+ (() => {+ const cardBody = document.querySelector(".card-body")+ if (cardBody) {+ const buttonDOM = document.createElement("div")+ buttonDOM.className = "mb-3 w-full text-right"+ buttonDOM.innerHTML = '<div><a class="btn btn-outline-primary" href="#{base_url <> "/" <> domain}" target="_blank">Open Dashboard</a></div>'+ cardBody.prepend(buttonDOM)+ }+ })()+ </script>+ """)+ ]+ end+def javascripts(%{assigns: %{context: "billing", resource: "enterprise_plan", changeset: %{}}}) do[Phoenix.HTML.raw("""diff --git a/lib/plausible_web/templates/layout/_header.html.heex b/lib/plausible_web/templates/layout/_header.html.heexindex f5cd4d944a..a266d926a7 100644--- a/lib/plausible_web/templates/layout/_header.html.heex+++ b/lib/plausible_web/templates/layout/_header.html.heex@@ -27,6 +27,18 @@<%= cond do %><% @conn.assigns[:current_user] -> %><ul class="flex items-center w-full sm:w-auto">+ <li :if={+ ee?() && @conn.assigns[:site] &&+ Plausible.Auth.is_super_admin?(@conn.assigns[:current_user])+ }>+ <.styled_link+ class="text-sm"+ href={PlausibleWeb.Endpoint.url() <> "/crm/sites/site/#{@conn.assigns[:site].id}"}+ new_tab={true}+ >+ CRM+ </.styled_link>+ </li><li:if={ee?() and Plausible.Users.on_trial?(@conn.assigns[:current_user])}class="hidden mr-6 sm:block"diff --git a/lib/plausible_web/templates/site/settings_people.html.heex b/lib/plausible_web/templates/site/settings_people.html.heexindex 8569f77834..1835915731 100644--- a/lib/plausible_web/templates/site/settings_people.html.heex+++ b/lib/plausible_web/templates/site/settings_people.html.heex@@ -20,6 +20,13 @@<div class="flex-1 min-w-0"><p class="text-sm font-medium text-gray-900 dark:text-gray-50 truncate"><%= membership.user.name %>+ <PlausibleWeb.Components.Generic.styled_link+ :if={ee?() and Plausible.Auth.is_super_admin?(@current_user)}+ new_tab={true}+ href={PlausibleWeb.Endpoint.url() <> "/crm/auth/user/#{@current_user.id}"}+ >+ CRM+ </PlausibleWeb.Components.Generic.styled_link></p><p class="text-sm text-gray-400 truncate"><%= membership.user.email %>diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex 708ce19176..96519be035 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -488,6 +488,31 @@ defmodule PlausibleWeb.SiteControllerTest doendend+ describe "GET /:website/settings/people" do+ setup [:create_user, :log_in, :create_site]++ @tag :ee_only+ test "shows members page with links to CRM for super admin", %{+ conn: conn,+ user: user,+ site: site+ } do+ patch_env(:super_admin_user_ids, [user.id])++ conn = get(conn, "/#{site.domain}/settings/people")+ resp = html_response(conn, 200)++ assert resp =~ "/crm/auth/user/#{user.id}"+ end++ test "does not show CRM links to non-super admin user", %{conn: conn, user: user, site: site} do+ conn = get(conn, "/#{site.domain}/settings/people")+ resp = html_response(conn, 200)++ refute resp =~ "/crm/auth/user/#{user.id}"+ end+ end+describe "GET /:website/settings/goals" dosetup [:create_user, :log_in, :create_site]diff --git a/test/plausible_web/controllers/stats_controller_test.exs b/test/plausible_web/controllers/stats_controller_test.exsindex 5d090e97b7..a2a95ab762 100644--- a/test/plausible_web/controllers/stats_controller_test.exs+++ b/test/plausible_web/controllers/stats_controller_test.exs@@ -99,6 +99,11 @@ defmodule PlausibleWeb.StatsControllerTest doconn = get(conn, "/" <> site.domain)assert html_response(conn, 404) =~ "There's nothing here"end++ test "does not show CRM link to the site", %{conn: conn, site: site} do+ conn = get(conn, "/" <> site.domain)+ refute html_response(conn, 200) =~ "/crm/sites/site/#{site.id}"+ endenddescribe "GET /:website - as a super admin" do@@ -152,6 +157,12 @@ defmodule PlausibleWeb.StatsControllerTest do[{"div", attrs, _}] = find(resp, @react_container)assert Enum.all?(attrs, fn {k, v} -> is_binary(k) and is_binary(v) end)end++ test "shows CRM link to the site", %{conn: conn} do+ site = insert(:site)+ conn = get(conn, "/" <> site.domain)+ assert html_response(conn, 200) =~ "/crm/sites/site/#{site.id}"+ endenddefp make_user_super_admin(%{user: user}) do