Skip to content

Commit 1807f77

Browse files
authored
feat(guard): add posthog integration (#597)
## πŸ“ Description Adds posthog integration to login/signup pages in the guard service. ## βœ… Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent 1fcac57 commit 1807f77

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

β€Žguard/config/config.exsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,7 @@ config :guard, Guard.OrganizationCleaner,
126126

127127
config :guard, :hard_destroy_grace_period_days, 30
128128

129+
config :guard, :posthog_api_key, ""
130+
config :guard, :posthog_host, "https://app.posthog.com"
131+
129132
import_config "#{config_env()}.exs"

β€Žguard/config/runtime.exsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ config :guard,
166166
:hide_gitlab_login_page,
167167
System.get_env("HIDE_GITLAB_LOGIN_PAGE") == "true"
168168

169+
config :guard, :posthog_api_key, System.get_env("POSTHOG_API_KEY")
170+
config :guard, :posthog_host, System.get_env("POSTHOG_HOST") || "https://app.posthog.com"
171+
169172
if System.get_env("AMQP_URL") != nil do
170173
config :amqp,
171174
connections: [

β€Žguard/lib/guard/id/api.exβ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ defmodule Guard.Id.Api do
188188
end
189189

190190
defp render_signup_page(conn, assigns) do
191+
assigns =
192+
Keyword.merge(assigns,
193+
posthog_api_key: Application.get_env(:guard, :posthog_api_key, ""),
194+
posthog_host: Application.get_env(:guard, :posthog_host, "https://app.posthog.com")
195+
)
196+
191197
html_content = Guard.TemplateRenderer.render_template([assigns: assigns], "signup.html")
192198

193199
conn
@@ -326,6 +332,12 @@ defmodule Guard.Id.Api do
326332
end
327333

328334
defp render_login_page(conn, assigns) do
335+
assigns =
336+
Keyword.merge(assigns,
337+
posthog_api_key: Application.get_env(:guard, :posthog_api_key, ""),
338+
posthog_host: Application.get_env(:guard, :posthog_host, "https://app.posthog.com")
339+
)
340+
329341
html_content = Guard.TemplateRenderer.render_template([assigns: assigns], "login.html")
330342

331343
conn

β€Žguard/templates/login.html.eexβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@
4141
<meta name="twitter:data1" content="1 minute" />
4242
<meta name="twitter:label2" content="Written by" />
4343
<meta name="twitter:data2" content="Semaphore Team" />
44+
<% if @assigns[:posthog_api_key] && @assigns[:posthog_api_key] != "" do %>
45+
<script>
46+
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init Ce js Ls Te Fs Ds capture Ye calculateEventProperties Us register register_once register_for_session unregister unregister_for_session Ws getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSurveysLoaded onSessionId getSurveys getActiveMatchingSurveys renderSurvey displaySurvey canRenderSurvey canRenderSurveyAsync identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty Bs zs createPersonProfile Hs Ms Gs opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing get_explicit_consent_status is_capturing clear_opt_in_out_capturing Ns debug L qs getPageViewId captureTraceFeedback captureTraceMetric".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
47+
48+
posthog.init('<%= @assigns[:posthog_api_key] %>', {
49+
api_host: '<%= @assigns[:posthog_host] %>',
50+
defaults: '2025-05-24',
51+
person_profiles: 'identified_only'
52+
});
53+
</script>
54+
<% end %>
4455
</head>
4556
<body class="page-template-default page page-id-19406 wp-embed-responsive no-sidebar">
4657
<div id="page" class="site no-header-no-footer green v8theme ">

β€Žguard/templates/signup.html.eexβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@
4444
<meta name="twitter:data1" content="1 minute">
4545
<meta name="twitter:label2" content="Written by">
4646
<meta name="twitter:data2" content="Semaphore Team">
47+
<% if @assigns[:posthog_api_key] && @assigns[:posthog_api_key] != "" do %>
48+
<script>
49+
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init Ce js Ls Te Fs Ds capture Ye calculateEventProperties Us register register_once register_for_session unregister unregister_for_session Ws getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSurveysLoaded onSessionId getSurveys getActiveMatchingSurveys renderSurvey displaySurvey canRenderSurvey canRenderSurveyAsync identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty Bs zs createPersonProfile Hs Ms Gs opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing get_explicit_consent_status is_capturing clear_opt_in_out_capturing Ns debug L qs getPageViewId captureTraceFeedback captureTraceMetric".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
50+
51+
posthog.init('<%= @assigns[:posthog_api_key] %>', {
52+
api_host: '<%= @assigns[:posthog_host] %>',
53+
defaults: '2025-05-24',
54+
person_profiles: 'identified_only'
55+
});
56+
</script>
57+
<% end %>
4758
</head>
4859
<body class="page-template-default page page-id-19406 wp-embed-responsive no-sidebar">
4960
<header>

0 commit comments

Comments
Β (0)