feat: Posthog integration (#9077)

# Which Problems Are Solved

- Adds a service in the console to enable Posthog integration based on
upon user environment variables

# How the Problems Are Solved

- A new service has been created in console for posthog
- This is only initiated based upon provided environment variables

# Additional Changes

N/A

# Additional Context

- Closes #[9076](https://github.com/zitadel/zitadel/issues/9076)
- Cannot be merged until this is completed
#[9070](https://github.com/zitadel/zitadel/issues/9070)
This commit is contained in:
David Skewis
2025-01-30 08:57:51 +02:00
committed by GitHub
parent e15094cdea
commit 4498f9c8f3
7 changed files with 81 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ import { ManagementService } from './services/mgmt.service';
import { ThemeService } from './services/theme.service';
import { UpdateService } from './services/update.service';
import { fallbackLanguage, supportedLanguages, supportedLanguagesRegexp } from './utils/language';
import { PosthogService } from './services/posthog.service';
@Component({
selector: 'cnsl-root',
@@ -68,6 +69,7 @@ export class AppComponent implements OnDestroy {
keyboardShortcuts: KeyboardShortcutsService,
private activatedRoute: ActivatedRoute,
@Inject(DOCUMENT) private document: Document,
private posthog: PosthogService,
) {
console.log(
'%cWait!',

View File

@@ -74,6 +74,7 @@ import { StorageService } from './services/storage.service';
import { ThemeService } from './services/theme.service';
import { ToastService } from './services/toast.service';
import { LanguagesService } from './services/languages.service';
import { PosthogService } from './services/posthog.service';
registerLocaleData(localeDe);
i18nIsoCountries.registerLocale(require('i18n-iso-countries/langs/de.json'));
@@ -242,6 +243,7 @@ const authConfig: AuthConfig = {
ToastService,
NavigationService,
LanguagesService,
PosthogService,
{ provide: 'windowObject', useValue: window },
],
bootstrap: [AppComponent],

View File

@@ -13,6 +13,8 @@ export interface Environment {
issuer: string;
customer_portal?: string;
instance_management_url?: string;
posthog_token?: string;
posthog_url?: string;
exhausted?: boolean;
}

View File

@@ -0,0 +1,43 @@
import { Injectable, OnDestroy } from '@angular/core';
import { EnvironmentService } from './environment.service';
import { Subscription } from 'rxjs';
import posthog from 'posthog-js';
@Injectable({
providedIn: 'root',
})
export class PosthogService implements OnDestroy {
private posthogToken?: string;
private posthogUrl?: string;
private envSubscription: Subscription;
constructor(private envService: EnvironmentService) {
this.envSubscription = this.envService.env.subscribe((env) => {
this.posthogToken = env.posthog_token;
this.posthogUrl = env.posthog_url;
this.init();
});
}
async init() {
if (this.posthogToken && this.posthogUrl) {
posthog.init(this.posthogToken, {
api_host: this.posthogUrl,
session_recording: {
maskAllInputs: true,
maskTextSelector: '*',
},
enable_heatmaps: true,
persistence: 'memory',
});
}
}
ngOnDestroy() {
if (this.envSubscription) {
this.envSubscription.unsubscribe();
}
posthog.reset();
}
}