postHog included

This commit is contained in:
2025-03-04 11:27:19 +01:00
parent 40814cfd2a
commit 69857bb8dc
7 changed files with 125 additions and 4 deletions

View File

@@ -1,11 +1,12 @@
// src/app/app.component.ts
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
import * as AOS from 'aos';
import { OverlayService } from './services/overlay.service';
import { Observable } from 'rxjs';
import { filter, Observable } from 'rxjs';
import { LoadingSpinnerComponent } from './components/loading-spinner.component';
import { PosthogService } from './services/posthog.service';
@Component({
selector: 'app-root',
@@ -45,7 +46,7 @@ export class AppComponent {
isLoading$: Observable<boolean>;
isSuccess$: Observable<boolean>;
constructor(private overlayService: OverlayService) {
constructor(private overlayService: OverlayService,private router: Router, private posthogService: PosthogService) {
this.isLoading$ = this.overlayService.loading$;
this.isSuccess$ = this.overlayService.success$;
}
@@ -55,6 +56,11 @@ export class AppComponent {
duration: 1000,
once: true,
});
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((event: NavigationEnd) => {
this.posthogService.capture('$pageview', { path: event.urlAfterRedirects });
});
}
ngAfterViewInit(): void {

View File

@@ -0,0 +1,31 @@
import { Injectable } from '@angular/core';
import posthog from 'posthog-js';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class PosthogService {
constructor() {
// Initialisierung kann alternativ hier statt in main.ts erfolgen
posthog.init(environment.POSTHOG_KEY, {
api_host: environment.POSTHOG_HOST,
capture_pageview: false // Wir steuern Seitenaufrufe manuell (siehe Schritt 4)
});
}
// Methode zum Erfassen eines benutzerdefinierten Events
capture(eventName: string, properties?: Record<string, any>) {
posthog.capture(eventName, properties);
}
// Benutzer identifizieren
identify(userId: string, properties?: Record<string, any>) {
posthog.identify(userId, properties);
}
// Feature Flags prüfen
isFeatureEnabled(flagKey: string): boolean {
return posthog.isFeatureEnabled(flagKey) || false;
}
}

View File

@@ -0,0 +1,4 @@
export const environment = {
POSTHOG_KEY:"phc_kA3JWHlvuSSi4QIAHastC1hETfCn1B8L1GZuoo281dO",
POSTHOG_HOST:"https://eu.i.posthog.com"
};

View File

@@ -0,0 +1,4 @@
export const environment = {
POSTHOG_KEY:"phc_kA3JWHlvuSSi4QIAHastC1hETfCn1B8L1GZuoo281dO",
POSTHOG_HOST:"https://eu.i.posthog.com"
};