From 418cc3a043d1b961ddd99bab911a10d20f8a9308 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Wed, 13 Aug 2025 18:21:01 -0500 Subject: [PATCH] posthog added --- bizmatch/package.json | 5 ++-- bizmatch/src/app/app.config.ts | 2 ++ bizmatch/src/app/services/posthog.factory.ts | 26 +++++++++++++++++++ bizmatch/src/environments/environment.base.ts | 3 +++ bizmatch/src/environments/environment.prod.ts | 5 +++- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 bizmatch/src/app/services/posthog.factory.ts diff --git a/bizmatch/package.json b/bizmatch/package.json index 4405d73..54ca2ba 100644 --- a/bizmatch/package.json +++ b/bizmatch/package.json @@ -49,10 +49,11 @@ "ngx-image-cropper": "^8.0.0", "ngx-mask": "^18.0.0", "ngx-quill": "^26.0.5", - "quill": "2.0.2", "ngx-sharebuttons": "^15.0.3", "ngx-stripe": "^18.1.0", "on-change": "^5.0.1", + "posthog-js": "^1.259.0", + "quill": "2.0.2", "rxjs": "~7.8.1", "tslib": "^2.6.3", "urlcat": "^3.1.0", @@ -78,4 +79,4 @@ "tailwindcss": "^3.4.4", "typescript": "~5.4.5" } -} \ No newline at end of file +} diff --git a/bizmatch/src/app/app.config.ts b/bizmatch/src/app/app.config.ts index a06db31..3cb02ce 100644 --- a/bizmatch/src/app/app.config.ts +++ b/bizmatch/src/app/app.config.ts @@ -16,6 +16,7 @@ import { AuthInterceptor } from './interceptors/auth.interceptor'; import { LoadingInterceptor } from './interceptors/loading.interceptor'; import { TimeoutInterceptor } from './interceptors/timeout.interceptor'; import { GlobalErrorHandler } from './services/globalErrorHandler'; +import { POSTHOG_INIT_PROVIDER } from './services/posthog.factory'; import { SelectOptionsService } from './services/select-options.service'; import { createLogger } from './utils/utils'; // provideClientHydration() @@ -67,6 +68,7 @@ export const appConfig: ApplicationConfig = { anchorScrolling: 'enabled', }), ), + ...(environment.production ? [POSTHOG_INIT_PROVIDER] : []), provideAnimations(), provideNgxStripe('pk_test_IlpbVQhxAXZypLgnCHOCqlj8'), provideQuillConfig({ diff --git a/bizmatch/src/app/services/posthog.factory.ts b/bizmatch/src/app/services/posthog.factory.ts new file mode 100644 index 0000000..a156b3b --- /dev/null +++ b/bizmatch/src/app/services/posthog.factory.ts @@ -0,0 +1,26 @@ +// posthog.factory.ts +import { isPlatformBrowser } from '@angular/common'; +import { APP_INITIALIZER, FactoryProvider, PLATFORM_ID, inject } from '@angular/core'; +import { environment } from '../../environments/environment'; + +export function initPosthog() { + const platformId = inject(PLATFORM_ID); + + // Nur Browser + nur Production + if (!isPlatformBrowser(platformId) || !environment.production) return () => {}; + + return async () => { + // Dynamisch laden -> eigener Chunk, wird in Dev nie gezogen + const { default: posthog } = await import('posthog-js'); + posthog.init(environment.POSTHOG_KEY, { + api_host: environment.POSTHOG_HOST, + capture_pageview: 'history_change', + }); + }; +} + +export const POSTHOG_INIT_PROVIDER: FactoryProvider = { + provide: APP_INITIALIZER, + useFactory: initPosthog, + multi: true, +}; diff --git a/bizmatch/src/environments/environment.base.ts b/bizmatch/src/environments/environment.base.ts index dcfd3fd..5a61704 100644 --- a/bizmatch/src/environments/environment.base.ts +++ b/bizmatch/src/environments/environment.base.ts @@ -16,4 +16,7 @@ export const environment_base = { appId: '1:1065122571067:web:1124571ab67bc0f5240d1e', measurementId: 'G-MHVDK1KSWV', }, + POSTHOG_KEY: '', + POSTHOG_HOST: '', + production: false, }; diff --git a/bizmatch/src/environments/environment.prod.ts b/bizmatch/src/environments/environment.prod.ts index 60aae84..b565709 100644 --- a/bizmatch/src/environments/environment.prod.ts +++ b/bizmatch/src/environments/environment.prod.ts @@ -1,7 +1,10 @@ import { environment_base } from './environment.base'; export const environment = environment_base; - +environment.production = true; environment.apiBaseUrl = 'https://api.bizmatch.net'; environment.mailinfoUrl = 'https://www.bizmatch.net'; environment.imageBaseUrl = 'https://www.bizmatch.net'; + +environment.POSTHOG_KEY = 'phc_eUIcIq0UPVzEDtZLy78klKhGudyagBz3goDlKx8SQFe'; +environment.POSTHOG_HOST = 'https://eu.i.posthog.com';