From 11d36fcd0076316ec0f14da3c769235b3ed4c5fe Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Tue, 7 Jan 2025 15:38:13 +0100 Subject: [PATCH] feat(console): allow to configure PostHog (#9135) # Which Problems Are Solved The console has no information about where and how to send PostHog events. # How the Problems Are Solved A PostHog API URL and token are passed through as plain text from the Zitadel runtime config to the environment.json. By default, no values are configured and the keys in the environment.json are omitted. # Additional Context - Closes https://github.com/zitadel/zitadel/issues/9070 - Complements https://github.com/zitadel/zitadel/pull/9077 --- cmd/defaults.yaml | 3 +++ internal/api/ui/console/console.go | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/defaults.yaml b/cmd/defaults.yaml index e993657123..868ee06866 100644 --- a/cmd/defaults.yaml +++ b/cmd/defaults.yaml @@ -611,6 +611,9 @@ Console: # 168h is 7 days, one week SharedMaxAge: 168h # ZITADEL_CONSOLE_LONGCACHE_SHAREDMAXAGE InstanceManagementURL: "" # ZITADEL_CONSOLE_INSTANCEMANAGEMENTURL + PostHog: + URL: "" # ZITADEL_CONSOLE_POSTHOG_URL + Token: "" # ZITADEL_CONSOLE_POSTHOG_TOKEN EncryptionKeys: DomainVerification: diff --git a/internal/api/ui/console/console.go b/internal/api/ui/console/console.go index 515f26db9b..fffbc00d5b 100644 --- a/internal/api/ui/console/console.go +++ b/internal/api/ui/console/console.go @@ -28,6 +28,10 @@ type Config struct { ShortCache middleware.CacheConfig LongCache middleware.CacheConfig InstanceManagementURL string + PostHog struct { + Token string + URL string + } } type spaHandler struct { @@ -117,7 +121,7 @@ func Start(config Config, externalSecure bool, issuer op.IssuerFromRequest, call return } limited := limitingAccessInterceptor.Limit(w, r) - environmentJSON, err := createEnvironmentJSON(url, issuer(r), instance.ConsoleClientID(), customerPortal, instanceMgmtURL, limited) + environmentJSON, err := createEnvironmentJSON(url, issuer(r), instance.ConsoleClientID(), customerPortal, instanceMgmtURL, config.PostHog.URL, config.PostHog.Token, limited) if err != nil { http.Error(w, fmt.Sprintf("unable to marshal env for console: %v", err), http.StatusInternalServerError) return @@ -150,13 +154,15 @@ func csp() *middleware.CSP { return &csp } -func createEnvironmentJSON(api, issuer, clientID, customerPortal, instanceMgmtUrl string, exhausted bool) ([]byte, error) { +func createEnvironmentJSON(api, issuer, clientID, customerPortal, instanceMgmtUrl, postHogURL, postHogToken string, exhausted bool) ([]byte, error) { environment := struct { API string `json:"api,omitempty"` Issuer string `json:"issuer,omitempty"` ClientID string `json:"clientid,omitempty"` CustomerPortal string `json:"customer_portal,omitempty"` InstanceManagementURL string `json:"instance_management_url,omitempty"` + PostHogURL string `json:"posthog_url,omitempty"` + PostHogToken string `json:"posthog_token,omitempty"` Exhausted bool `json:"exhausted,omitempty"` }{ API: api, @@ -164,6 +170,8 @@ func createEnvironmentJSON(api, issuer, clientID, customerPortal, instanceMgmtUr ClientID: clientID, CustomerPortal: customerPortal, InstanceManagementURL: instanceMgmtUrl, + PostHogURL: postHogURL, + PostHogToken: postHogToken, Exhausted: exhausted, } return json.Marshal(environment)