mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-07 22:55:12 +00:00
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:
@@ -13,6 +13,8 @@ export interface Environment {
|
||||
issuer: string;
|
||||
customer_portal?: string;
|
||||
instance_management_url?: string;
|
||||
posthog_token?: string;
|
||||
posthog_url?: string;
|
||||
exhausted?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user