Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Implement user notes in CRM and HelpScout integration (#4611)

Adrian Gruntkowski9d997a74d6ba
diff --git a/extra/lib/plausible/help_scout.ex b/extra/lib/plausible/help_scout.ex
index 15698a96b7..9cc5a7d428 100644
--- a/extra/lib/plausible/help_scout.ex
+++ b/extra/lib/plausible/help_scout.ex
@@ -88,6 +88,7 @@ defmodule Plausible.HelpScout do
{:ok,
%{
email: user.email,
+ notes: user.notes,
status_label: status_label(user),
status_link:
Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :show, :auth, :user, user.id),
diff --git a/extra/lib/plausible_web/views/help_scout_view.ex b/extra/lib/plausible_web/views/help_scout_view.ex
index fbbd6f19d8..8a3b8c1bc2 100644
--- a/extra/lib/plausible_web/views/help_scout_view.ex
+++ b/extra/lib/plausible_web/views/help_scout_view.ex
@@ -42,6 +42,17 @@ defmodule PlausibleWeb.HelpScoutView do
<p class="label">
Owner of <b><a href={@sites_link} target="_blank"><%= @sites_count %> sites</a></b>
</p>
+ <p class="value"></p>
+ </div>
+
+ <div :if={@notes} class="notes">
+ <p class="label">
+ <b>Notes</b>
+ </p>
+
+ <div class="value">
+ <%= Phoenix.HTML.Format.text_to_html(@notes, escape: true) %>
+ </div>
</div>
<% end %>
</.layout>
@@ -140,6 +151,10 @@ defmodule PlausibleWeb.HelpScoutView do
margin-bottom: 1.25em;
font-weight: bold;
}
+
+ .notes .value {
+ font-weight: normal;
+ }
</style>
</head>
diff --git a/lib/plausible/auth/user.ex b/lib/plausible/auth/user.ex
index 539fc09043..4fe35b9f32 100644
--- a/lib/plausible/auth/user.ex
+++ b/lib/plausible/auth/user.ex
@@ -35,6 +35,9 @@ defmodule Plausible.Auth.User do
field :previous_email, :string
field :accept_traffic_until, :date
+ # Field for purely informational purposes in CRM context
+ field :notes, :string
+
# A field only used as a manual override - allow subscribing
# to any plan, even when exceeding its pageview limit
field :allow_next_upgrade_override, :boolean
@@ -113,7 +116,8 @@ defmodule Plausible.Auth.User do
:theme,
:trial_expiry_date,
:allow_next_upgrade_override,
- :accept_traffic_until
+ :accept_traffic_until,
+ :notes
])
|> validate_required([:email, :name, :email_verified])
|> maybe_bump_accept_traffic_until()
diff --git a/lib/plausible/auth/user_admin.ex b/lib/plausible/auth/user_admin.ex
index 21eec38e95..baf107d2a9 100644
--- a/lib/plausible/auth/user_admin.ex
+++ b/lib/plausible/auth/user_admin.ex
@@ -20,7 +20,8 @@ defmodule Plausible.Auth.UserAdmin do
allow_next_upgrade_override: nil,
accept_traffic_until: %{
help_text: "Change will take up to 15 minutes to propagate"
- }
+ },
+ notes: %{type: :textarea, rows: 6}
]
end
diff --git a/test/plausible_web/controllers/help_scout_controller_test.exs b/test/plausible_web/controllers/help_scout_controller_test.exs
index 51d16fb1d6..cda615f6cb 100644
--- a/test/plausible_web/controllers/help_scout_controller_test.exs
+++ b/test/plausible_web/controllers/help_scout_controller_test.exs
@@ -104,9 +104,9 @@ defmodule PlausibleWeb.HelpScoutControllerTest do
end
end
- describe "shows/2" do
+ describe "show/2" do
test "returns details on success", %{conn: conn} do
- user = insert(:user, email: "[email protected]")
+ user = insert(:user, email: "[email protected]", notes: "Some note\nwith new line")
conn =
conn
@@ -115,7 +115,9 @@ defmodule PlausibleWeb.HelpScoutControllerTest do
"/helpscout/show?conversation_id=123&customer_id=500&[email protected]"
)
- assert html_response(conn, 200) =~ "/crm/auth/user/#{user.id}"
+ assert html = html_response(conn, 200)
+ assert html =~ "/crm/auth/user/#{user.id}"
+ assert html =~ "Some note<br>\nwith new line"
end
test "returns error when cookie is missing", %{conn: conn} do