@dereekb/dbx-analytics 13.10.2 → 13.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,23 @@ var DbxAnalyticsStreamEventType;
53
53
  * A generic custom analytics event.
54
54
  */
55
55
  DbxAnalyticsStreamEventType[DbxAnalyticsStreamEventType["Event"] = 7] = "Event";
56
+ // Session Replay
57
+ /**
58
+ * Request to start session replay recording.
59
+ */
60
+ DbxAnalyticsStreamEventType[DbxAnalyticsStreamEventType["StartSessionRecording"] = 8] = "StartSessionRecording";
61
+ /**
62
+ * Request to stop session replay recording.
63
+ */
64
+ DbxAnalyticsStreamEventType[DbxAnalyticsStreamEventType["StopSessionRecording"] = 9] = "StopSessionRecording";
65
+ /**
66
+ * Request to pause an active session replay recording without clearing it.
67
+ */
68
+ DbxAnalyticsStreamEventType[DbxAnalyticsStreamEventType["PauseSessionRecording"] = 10] = "PauseSessionRecording";
69
+ /**
70
+ * Request to resume a previously paused session replay recording.
71
+ */
72
+ DbxAnalyticsStreamEventType[DbxAnalyticsStreamEventType["ResumeSessionRecording"] = 11] = "ResumeSessionRecording";
56
73
  })(DbxAnalyticsStreamEventType || (DbxAnalyticsStreamEventType = {}));
57
74
 
58
75
  /**
@@ -358,6 +375,39 @@ class DbxAnalyticsService {
358
375
  name: page
359
376
  }, DbxAnalyticsStreamEventType.PageView);
360
377
  }
378
+ /**
379
+ * Requests that opt-in listeners (e.g. Mixpanel) start session replay recording.
380
+ *
381
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.StartSessionRecording} event. Listeners
382
+ * that don't handle session replay (e.g. Segment) ignore it.
383
+ */
384
+ startSessionRecording() {
385
+ this.sendNextEvent({}, DbxAnalyticsStreamEventType.StartSessionRecording);
386
+ }
387
+ /**
388
+ * Requests that opt-in listeners stop session replay recording.
389
+ *
390
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.StopSessionRecording} event.
391
+ */
392
+ stopSessionRecording() {
393
+ this.sendNextEvent({}, DbxAnalyticsStreamEventType.StopSessionRecording);
394
+ }
395
+ /**
396
+ * Requests that opt-in listeners pause active session replay recording without clearing it.
397
+ *
398
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.PauseSessionRecording} event.
399
+ */
400
+ pauseSessionRecording() {
401
+ this.sendNextEvent({}, DbxAnalyticsStreamEventType.PauseSessionRecording);
402
+ }
403
+ /**
404
+ * Requests that opt-in listeners resume previously paused session replay recording.
405
+ *
406
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.ResumeSessionRecording} event.
407
+ */
408
+ resumeSessionRecording() {
409
+ this.sendNextEvent({}, DbxAnalyticsStreamEventType.ResumeSessionRecording);
410
+ }
361
411
  /**
362
412
  * Sends the next event.
363
413
  *
@@ -527,6 +577,197 @@ function provideDbxAnalyticsService(config) {
527
577
  return makeEnvironmentProviders(providers);
528
578
  }
529
579
 
580
+ /**
581
+ * Injection token for optionally preloading the Mixpanel SDK on the page.
582
+ *
583
+ * In typical setups Mixpanel is loaded by Segment device mode, so this token is rarely needed.
584
+ */
585
+ const PRELOAD_MIXPANEL_TOKEN = new InjectionToken('DbxAnalyticsMixpanelApiServicePreload');
586
+ /**
587
+ * Configuration for the Mixpanel analytics integration.
588
+ *
589
+ * Unlike {@link DbxAnalyticsSegmentApiServiceConfig}, this config does not take a write key —
590
+ * Mixpanel is initialized by Segment device mode. The `active` and `logging` flags exist for
591
+ * parity with the Segment config and to gate listener behavior.
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * const config = new DbxAnalyticsMixpanelApiServiceConfig();
596
+ * config.active = environment.production;
597
+ * config.logging = !environment.production;
598
+ * ```
599
+ */
600
+ class DbxAnalyticsMixpanelApiServiceConfig {
601
+ logging = true;
602
+ active = true;
603
+ }
604
+ /**
605
+ * Service that manages async access to the Mixpanel JS SDK exposed on `window.mixpanel`.
606
+ *
607
+ * The Mixpanel SDK is typically loaded by Segment's Mixpanel (Actions) device-mode destination,
608
+ * so this service waits for `window.mixpanel` to exist using the inherited window-loading polling.
609
+ * The resolved SDK instance is available via the inherited `service$` observable.
610
+ *
611
+ * Provided via {@link provideDbxAnalyticsMixpanelApiService}.
612
+ *
613
+ * @example
614
+ * ```ts
615
+ * // In app.config.ts
616
+ * provideDbxAnalyticsMixpanelApiService({
617
+ * dbxAnalyticsMixpanelApiServiceConfigFactory: () => {
618
+ * const config = new DbxAnalyticsMixpanelApiServiceConfig();
619
+ * config.active = environment.production;
620
+ * return config;
621
+ * }
622
+ * })
623
+ * ```
624
+ */
625
+ class DbxAnalyticsMixpanelApiService extends AbstractAsyncWindowLoadedService {
626
+ _config = inject(DbxAnalyticsMixpanelApiServiceConfig);
627
+ static MIXPANEL_API_WINDOW_KEY = 'mixpanel';
628
+ constructor() {
629
+ const preload = inject(PRELOAD_MIXPANEL_TOKEN, { optional: true });
630
+ super(DbxAnalyticsMixpanelApiService.MIXPANEL_API_WINDOW_KEY, undefined, 'Mixpanel', preload);
631
+ }
632
+ get config() {
633
+ return this._config;
634
+ }
635
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: DbxAnalyticsMixpanelApiService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
636
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: DbxAnalyticsMixpanelApiService });
637
+ }
638
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: DbxAnalyticsMixpanelApiService, decorators: [{
639
+ type: Injectable
640
+ }], ctorParameters: () => [] });
641
+
642
+ /**
643
+ * Analytics listener that forwards session-replay control events to the Mixpanel SDK.
644
+ *
645
+ * Handles only the four session-replay event types — track/identify/page events are intentionally
646
+ * not forwarded here because Segment's Mixpanel (Actions) device-mode destination already routes
647
+ * them to Mixpanel. Forwarding them again would produce duplicate events.
648
+ *
649
+ * - {@link DbxAnalyticsStreamEventType.StartSessionRecording} -> `mixpanel.start_session_recording()`
650
+ * - {@link DbxAnalyticsStreamEventType.StopSessionRecording} -> `mixpanel.stop_session_recording()`
651
+ * - {@link DbxAnalyticsStreamEventType.PauseSessionRecording} -> `mixpanel.pause_session_recording()`
652
+ * - {@link DbxAnalyticsStreamEventType.ResumeSessionRecording} -> `mixpanel.resume_session_recording()`
653
+ *
654
+ * Events are only sent when the Mixpanel configuration is marked as `active`.
655
+ * Provided at root level and registered as a listener via {@link DbxAnalyticsServiceConfiguration.listeners}.
656
+ */
657
+ class DbxAnalyticsMixpanelServiceListener extends AbstractDbxAnalyticsServiceListener {
658
+ _mixpanelApi = inject(DbxAnalyticsMixpanelApiService);
659
+ constructor() {
660
+ super();
661
+ if (this._mixpanelApi.config.logging) {
662
+ console.log('MixpanelAnalyticsListenerService: Mixpanel is logging events.');
663
+ }
664
+ if (!this._mixpanelApi.config.active) {
665
+ console.log('MixpanelAnalyticsListenerService: Mixpanel is disabled from sending events to the server.');
666
+ }
667
+ }
668
+ _initializeServiceSubscription() {
669
+ return combineLatest([this._mixpanelApi.service$, this.analyticsEvents$]).subscribe(([mixpanel, streamEvent]) => {
670
+ if (this._mixpanelApi.config.logging) {
671
+ console.log('Mixpanel Listener Logging Event: ', streamEvent);
672
+ }
673
+ if (this._mixpanelApi.config.active) {
674
+ this.handleStreamEvent(mixpanel, streamEvent);
675
+ }
676
+ });
677
+ }
678
+ /**
679
+ * Routes a session-replay control event to the corresponding Mixpanel SDK method.
680
+ *
681
+ * Non-session-replay events are intentionally ignored — Segment's device-mode integration
682
+ * already forwards track/identify/page to Mixpanel.
683
+ *
684
+ * @param api - The loaded Mixpanel SDK instance
685
+ * @param streamEvent - The analytics event to process
686
+ */
687
+ handleStreamEvent(api, streamEvent) {
688
+ switch (streamEvent.type) {
689
+ case DbxAnalyticsStreamEventType.StartSessionRecording:
690
+ api.start_session_recording();
691
+ break;
692
+ case DbxAnalyticsStreamEventType.StopSessionRecording:
693
+ api.stop_session_recording();
694
+ break;
695
+ case DbxAnalyticsStreamEventType.PauseSessionRecording:
696
+ api.pause_session_recording();
697
+ break;
698
+ case DbxAnalyticsStreamEventType.ResumeSessionRecording:
699
+ api.resume_session_recording();
700
+ break;
701
+ default:
702
+ // All other event types are routed to Mixpanel by Segment's device-mode destination.
703
+ break;
704
+ }
705
+ }
706
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: DbxAnalyticsMixpanelServiceListener, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
707
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: DbxAnalyticsMixpanelServiceListener, providedIn: 'root' });
708
+ }
709
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: DbxAnalyticsMixpanelServiceListener, decorators: [{
710
+ type: Injectable,
711
+ args: [{
712
+ providedIn: 'root'
713
+ }]
714
+ }], ctorParameters: () => [] });
715
+
716
+ /**
717
+ * Creates Angular environment providers that register {@link DbxAnalyticsMixpanelApiService} for Mixpanel session-replay control.
718
+ *
719
+ * Use alongside {@link provideDbxAnalyticsService} to wire Mixpanel as an analytics listener that
720
+ * handles session-replay start/stop/pause/resume events.
721
+ *
722
+ * @param config - Mixpanel-specific configuration
723
+ * @returns environment providers for Mixpanel analytics
724
+ *
725
+ * @example
726
+ * ```ts
727
+ * // In app.config.ts
728
+ * export const appConfig: ApplicationConfig = {
729
+ * providers: [
730
+ * provideDbxAnalyticsMixpanelApiService({
731
+ * dbxAnalyticsMixpanelApiServiceConfigFactory: () => {
732
+ * const config = new DbxAnalyticsMixpanelApiServiceConfig();
733
+ * config.active = environment.production;
734
+ * return config;
735
+ * }
736
+ * }),
737
+ * provideDbxAnalyticsService({
738
+ * dbxAnalyticsServiceConfigurationFactory: (injector) => ({
739
+ * isProduction: environment.production,
740
+ * listeners: [
741
+ * injector.get(DbxAnalyticsSegmentServiceListener),
742
+ * injector.get(DbxAnalyticsMixpanelServiceListener)
743
+ * ]
744
+ * })
745
+ * })
746
+ * ]
747
+ * };
748
+ * ```
749
+ */
750
+ function provideDbxAnalyticsMixpanelApiService(config) {
751
+ const { preloadMixpanelToken, dbxAnalyticsMixpanelApiServiceConfigFactory } = config;
752
+ const providers = [
753
+ // configuration
754
+ {
755
+ provide: DbxAnalyticsMixpanelApiServiceConfig,
756
+ useFactory: dbxAnalyticsMixpanelApiServiceConfigFactory,
757
+ deps: [Injector]
758
+ },
759
+ // service
760
+ DbxAnalyticsMixpanelApiService
761
+ ];
762
+ if (preloadMixpanelToken) {
763
+ providers.push({
764
+ provide: PRELOAD_MIXPANEL_TOKEN,
765
+ useValue: preloadMixpanelToken
766
+ });
767
+ }
768
+ return makeEnvironmentProviders(providers);
769
+ }
770
+
530
771
  /**
531
772
  * Injection token for optionally preloading the Segment analytics script.
532
773
  */
@@ -694,7 +935,11 @@ class DbxAnalyticsSegmentServiceListener extends AbstractDbxAnalyticsServiceList
694
935
  break;
695
936
  case DbxAnalyticsStreamEventType.UserIdChange:
696
937
  case DbxAnalyticsStreamEventType.UserPropertiesEvent:
697
- // These event types are not forwarded to Segment
938
+ case DbxAnalyticsStreamEventType.StartSessionRecording:
939
+ case DbxAnalyticsStreamEventType.StopSessionRecording:
940
+ case DbxAnalyticsStreamEventType.PauseSessionRecording:
941
+ case DbxAnalyticsStreamEventType.ResumeSessionRecording:
942
+ // These event types are not forwarded to Segment.
698
943
  break;
699
944
  }
700
945
  }
@@ -814,5 +1059,5 @@ function provideDbxAnalyticsSegmentApiService(config) {
814
1059
  * Generated bundle index. Do not edit.
815
1060
  */
816
1061
 
817
- export { AbstractDbxAnalyticsServiceListener, DbxActionAnalyticsDirective, DbxAnalyticsActionModule, DbxAnalyticsEventEmitterService, DbxAnalyticsEventStreamService, DbxAnalyticsSegmentApiService, DbxAnalyticsSegmentApiServiceConfig, DbxAnalyticsSegmentServiceListener, DbxAnalyticsService, DbxAnalyticsServiceConfiguration, DbxAnalyticsServiceListener, DbxAnalyticsStreamEventType, DbxAnalyticsUserSource, PRELOAD_SEGMENT_TOKEN, dbxAnalyticsStreamEventAnalyticsEventWrapper, provideDbxAnalyticsSegmentApiService, provideDbxAnalyticsService };
1062
+ export { AbstractDbxAnalyticsServiceListener, DbxActionAnalyticsDirective, DbxAnalyticsActionModule, DbxAnalyticsEventEmitterService, DbxAnalyticsEventStreamService, DbxAnalyticsMixpanelApiService, DbxAnalyticsMixpanelApiServiceConfig, DbxAnalyticsMixpanelServiceListener, DbxAnalyticsSegmentApiService, DbxAnalyticsSegmentApiServiceConfig, DbxAnalyticsSegmentServiceListener, DbxAnalyticsService, DbxAnalyticsServiceConfiguration, DbxAnalyticsServiceListener, DbxAnalyticsStreamEventType, DbxAnalyticsUserSource, PRELOAD_MIXPANEL_TOKEN, PRELOAD_SEGMENT_TOKEN, dbxAnalyticsStreamEventAnalyticsEventWrapper, provideDbxAnalyticsMixpanelApiService, provideDbxAnalyticsSegmentApiService, provideDbxAnalyticsService };
818
1063
  //# sourceMappingURL=dereekb-dbx-analytics.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"dereekb-dbx-analytics.mjs","sources":["../../../../packages/dbx-analytics/src/lib/analytics/analytics.stream.ts","../../../../packages/dbx-analytics/src/lib/analytics/analytics.service.ts","../../../../packages/dbx-analytics/src/lib/action/analytics.action.directive.ts","../../../../packages/dbx-analytics/src/lib/action/analytics.module.ts","../../../../packages/dbx-analytics/src/lib/analytics/analytics.providers.ts","../../../../packages/dbx-analytics/src/lib/providers/segment/segment.service.ts","../../../../packages/dbx-analytics/src/lib/providers/segment/segment.listener.service.ts","../../../../packages/dbx-analytics/src/lib/providers/segment/segment.providers.ts","../../../../packages/dbx-analytics/src/dereekb-dbx-analytics.ts"],"sourcesContent":["import { type Maybe } from '@dereekb/util';\nimport { type AnalyticsUser, type UserAnalyticsEvent, type AnalyticsUserId } from './analytics';\n\n/**\n * Categorizes the kind of analytics stream event emitted by {@link DbxAnalyticsService}.\n *\n * Listeners use this type to route events to the appropriate analytics provider method\n * (e.g., Segment `track()`, `identify()`, `page()`).\n */\nexport enum DbxAnalyticsStreamEventType {\n /**\n * A page/screen view event, typically sent on route transitions.\n */\n PageView,\n /**\n * Emitted any time the user value changes, including when transitioning from defined to undefined.\n *\n * Used by listeners to update the identified user in analytics providers.\n */\n UserChange,\n /**\n * Emitted only when the user's unique ID changes, filtering out property-only updates.\n *\n * Useful for triggering identity calls without redundant updates when only traits change.\n */\n UserIdChange,\n\n // User Events\n /**\n * A new user registration event.\n */\n NewUserEvent,\n /**\n * A returning user login event.\n */\n UserLoginEvent,\n /**\n * A user logout event.\n */\n UserLogoutEvent,\n /**\n * An update to user profile properties/traits.\n */\n UserPropertiesEvent,\n\n // Events\n /**\n * A generic custom analytics event.\n */\n Event\n}\n\n/**\n * Represents a single event in the analytics stream, combining the event type, payload, and user context.\n *\n * Emitted by {@link DbxAnalyticsService} and consumed by {@link DbxAnalyticsServiceListener} implementations\n * (e.g., {@link DbxAnalyticsSegmentServiceListener}) to forward events to external analytics providers.\n *\n * @example\n * ```ts\n * // Subscribe to the analytics event stream\n * analyticsService.events$.subscribe((streamEvent: DbxAnalyticsStreamEvent) => {\n * console.log(streamEvent.type, streamEvent.event?.name, streamEvent.userId);\n * });\n * ```\n */\nexport interface DbxAnalyticsStreamEvent {\n readonly type: DbxAnalyticsStreamEventType;\n readonly user?: Maybe<AnalyticsUser>;\n readonly event?: UserAnalyticsEvent;\n readonly userId?: AnalyticsUserId;\n}\n","import { type Observable, Subject, BehaviorSubject, of, type Subscription, first, shareReplay, switchMap, distinctUntilChanged } from 'rxjs';\nimport { Injectable, inject } from '@angular/core';\nimport { SubscriptionObject, filterMaybe } from '@dereekb/rxjs';\nimport { type AnalyticsEvent, type AnalyticsEventData, type AnalyticsEventName, type AnalyticsUser, type NewUserAnalyticsEventData, type UserAnalyticsEvent } from './analytics';\nimport { type DbxAnalyticsStreamEvent, DbxAnalyticsStreamEventType } from './analytics.stream';\nimport { type Maybe, type Destroyable, safeCompareEquality } from '@dereekb/util';\n\n/**\n * Abstract emitter interface for sending analytics events.\n *\n * Implemented by {@link DbxAnalyticsService} as the primary concrete implementation.\n * Components and services use this to fire analytics events without coupling to a specific provider.\n *\n * @example\n * ```ts\n * // Inject and send a custom event\n * const emitter = inject(DbxAnalyticsEventEmitterService);\n * emitter.sendEventData('Button Clicked', { buttonId: 'save' });\n * ```\n */\nexport abstract class DbxAnalyticsEventEmitterService {\n abstract sendNewUserEvent(user: AnalyticsUser, data: NewUserAnalyticsEventData): void;\n abstract sendUserLoginEvent(user: AnalyticsUser, data?: AnalyticsEventData): void;\n abstract sendUserLogoutEvent(data?: AnalyticsEventData): void;\n abstract sendUserPropertiesEvent(user: AnalyticsUser, data?: AnalyticsEventData): void;\n /**\n * @deprecated When sending an event with no data, use {@link sendEventType} instead.\n */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n abstract sendEventData(name: AnalyticsEventName): void;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n abstract sendEventData(name: AnalyticsEventName, data: AnalyticsEventData): void;\n abstract sendEvent(event: AnalyticsEvent): void;\n abstract sendPageView(page?: string): void;\n}\n\n/**\n * Abstract interface exposing the analytics event stream as an observable.\n *\n * Implemented by {@link DbxAnalyticsService}. Listeners subscribe to `events$` to forward events to external providers.\n */\nexport abstract class DbxAnalyticsEventStreamService {\n abstract readonly events$: Observable<DbxAnalyticsStreamEvent>;\n}\n\n/**\n * Abstract source for the current analytics user identity.\n *\n * Provide an implementation to automatically associate a user with all emitted analytics events.\n * Typically backed by the auth system (e.g., {@link DbxFirebaseAnalyticsUserSource}).\n *\n * @example\n * ```ts\n * // Provide a static user source\n * const userSource: DbxAnalyticsUserSource = {\n * analyticsUser$: of({ user: 'uid_abc123', properties: { role: 'admin' } })\n * };\n * ```\n */\nexport abstract class DbxAnalyticsUserSource {\n abstract readonly analyticsUser$: Observable<Maybe<AnalyticsUser>>;\n}\n\n/**\n * Abstract listener that receives analytics events from {@link DbxAnalyticsService}.\n *\n * Implement this to forward events to an external analytics provider (e.g., Segment, Mixpanel).\n * Register listeners via {@link DbxAnalyticsServiceConfiguration.listeners}.\n */\nexport abstract class DbxAnalyticsServiceListener {\n public abstract listenToService(service: DbxAnalyticsService): void;\n}\n\n/**\n * Base class for analytics service listeners that manages subscription lifecycle and provides\n * reactive access to the analytics service and its event stream.\n *\n * Subclasses implement {@link _initializeServiceSubscription} to subscribe to events and forward them\n * to an external analytics provider.\n *\n * @example\n * ```ts\n * class MyAnalyticsListener extends AbstractDbxAnalyticsServiceListener {\n * protected _initializeServiceSubscription(): Subscription | false {\n * return this.analyticsEvents$.subscribe((event) => {\n * console.log('Event:', event.type, event.event?.name);\n * });\n * }\n * }\n * ```\n */\nexport abstract class AbstractDbxAnalyticsServiceListener implements DbxAnalyticsServiceListener, Destroyable {\n private _sub = new SubscriptionObject();\n protected _analytics = new BehaviorSubject<Maybe<DbxAnalyticsService>>(undefined);\n\n readonly analytics$ = this._analytics.pipe(filterMaybe(), shareReplay(1));\n readonly analyticsEvents$ = this.analytics$.pipe(\n switchMap((x) => x.events$),\n shareReplay(1)\n );\n\n // MARK: AnalyticsServiceListener\n listenToService(service: DbxAnalyticsService): void {\n this._analytics.next(service);\n const sub = this._initializeServiceSubscription();\n\n if (sub !== false) {\n this._sub.subscription = sub;\n }\n }\n\n protected abstract _initializeServiceSubscription(): Subscription | false;\n\n // MARK: Destroy\n destroy(): void {\n this._analytics.complete();\n this._sub.destroy();\n }\n}\n\n/**\n * Configuration for {@link DbxAnalyticsService}, controlling which listeners receive events,\n * whether analytics runs in production mode, and optionally providing a user source.\n *\n * In non-production mode, listeners are not initialized and all events are logged to the console instead.\n * Provide via {@link provideDbxAnalyticsService} using a factory function.\n *\n * @example\n * ```ts\n * const config: DbxAnalyticsServiceConfiguration = {\n * isProduction: environment.production,\n * logEvents: !environment.production,\n * listeners: [segmentListener],\n * userSource: firebaseAnalyticsUserSource\n * };\n * ```\n */\nexport abstract class DbxAnalyticsServiceConfiguration {\n readonly listeners: DbxAnalyticsServiceListener[] = [];\n readonly isProduction?: boolean;\n readonly logEvents?: boolean;\n readonly userSource?: DbxAnalyticsUserSource;\n}\n\n/**\n * A fully resolved analytics stream event that includes the event payload, type, user context, and extracted user ID.\n *\n * Created by {@link dbxAnalyticsStreamEventAnalyticsEventWrapper} and emitted through the analytics event stream.\n */\nexport interface DbxAnalyticsStreamEventAnalyticsEventWrapper extends DbxAnalyticsStreamEvent {\n readonly event: UserAnalyticsEvent;\n readonly type: DbxAnalyticsStreamEventType;\n readonly user: Maybe<AnalyticsUser>;\n readonly userId: string | undefined;\n}\n\n/**\n * Wraps a {@link UserAnalyticsEvent} into a {@link DbxAnalyticsStreamEventAnalyticsEventWrapper},\n * extracting the user ID for convenient access by listeners.\n *\n * @param event - the analytics event with optional user context\n * @param type - the stream event type classification; defaults to `Event`\n * @returns a wrapper combining the event, type, user, and extracted userId\n *\n * @example\n * ```ts\n * const wrapper = dbxAnalyticsStreamEventAnalyticsEventWrapper(\n * { name: 'Button Clicked', user: { user: 'uid_123' } },\n * DbxAnalyticsStreamEventType.Event\n * );\n * // wrapper.userId === 'uid_123'\n * ```\n */\nexport function dbxAnalyticsStreamEventAnalyticsEventWrapper(event: UserAnalyticsEvent, type: DbxAnalyticsStreamEventType = DbxAnalyticsStreamEventType.Event) {\n const { user } = event;\n const userId = user ? user.user : undefined;\n\n return {\n event,\n type,\n user,\n userId\n };\n}\n\n/**\n * Central analytics service that emits typed analytics events for consumption by registered listeners.\n *\n * Acts as both the event emitter (components call methods like {@link sendEventData}, {@link sendPageView})\n * and the event stream source (listeners subscribe to {@link events$}).\n *\n * In production mode, registered {@link DbxAnalyticsServiceListener} instances (e.g., Segment) receive all events.\n * In non-production mode, events are logged to the console for debugging.\n *\n * Provided via {@link provideDbxAnalyticsService} with a {@link DbxAnalyticsServiceConfiguration} factory.\n *\n * @example\n * ```ts\n * // Send a custom event from a component\n * const analytics = inject(DbxAnalyticsService);\n * analytics.sendEventData('Interview Started', { candidateId: 'abc123' });\n *\n * // Send a page view on route transitions\n * transitionService.onSuccess({}, () => {\n * analytics.sendPageView();\n * });\n * ```\n */\n@Injectable()\nexport class DbxAnalyticsService implements DbxAnalyticsEventStreamService, DbxAnalyticsEventEmitterService, Destroyable {\n private readonly _config = inject(DbxAnalyticsServiceConfiguration);\n\n // TODO: Make these configurable.\n static readonly USER_REGISTRATION_EVENT_NAME = 'User Registered';\n static readonly USER_LOGIN_EVENT_NAME = 'User Login';\n static readonly USER_LOGOUT_EVENT_NAME = 'User Logout';\n static readonly USER_PROPERTIES_EVENT_NAME = 'User Properties';\n\n private _subject = new Subject<DbxAnalyticsStreamEvent>();\n readonly events$ = this._subject.asObservable();\n\n private _userSource = new BehaviorSubject<Maybe<DbxAnalyticsUserSource>>(undefined);\n\n readonly user$ = this._userSource.pipe(\n switchMap((x) => (x ? x.analyticsUser$ : of(undefined))),\n shareReplay(1)\n );\n\n private _userSourceSub = new SubscriptionObject();\n private _userIdEventSub = new SubscriptionObject();\n private _loggerSub = new SubscriptionObject();\n\n constructor() {\n this._init();\n let userSource: Maybe<DbxAnalyticsUserSource> = inject(DbxAnalyticsUserSource, { optional: true });\n userSource = userSource || this._config.userSource;\n\n if (userSource) {\n this.setUserSource(userSource);\n }\n }\n\n // MARK: Source\n /**\n * Sets the analytics user directly, overriding any configured {@link DbxAnalyticsUserSource}.\n *\n * Pass `undefined` to clear the current user (e.g., on logout).\n *\n * @param user - the user to identify, or undefined to clear\n */\n public setUser(user: Maybe<AnalyticsUser>): void {\n let source: Maybe<DbxAnalyticsUserSource>;\n\n if (user) {\n source = { analyticsUser$: of(user) };\n }\n\n this._userSource.next(source);\n\n if (this._userSource.value) {\n console.warn('DbxAnalyticsService has a userSource that is set. Source is now overridden by setUser() value.');\n }\n }\n\n /**\n * Sets the reactive user source that automatically updates the analytics user as auth state changes.\n *\n * @param source - the user source providing an observable of the current analytics user\n */\n public setUserSource(source: DbxAnalyticsUserSource): void {\n this._userSource.next(source);\n }\n\n // MARK: DbxAnalyticsEventEmitterService\n /**\n * Emits a new user registration event, typically sent once after account creation.\n *\n * @param user - the newly registered user\n * @param data - registration-specific data including the signup method\n */\n public sendNewUserEvent(user: AnalyticsUser, data: NewUserAnalyticsEventData): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_REGISTRATION_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.NewUserEvent,\n user\n );\n }\n\n /**\n * Emits a user login event, identifying the user in analytics providers.\n *\n * @param user - the user who logged in\n * @param data - optional additional event data\n */\n public sendUserLoginEvent(user: AnalyticsUser, data?: AnalyticsEventData): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_LOGIN_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.UserLoginEvent,\n user\n );\n }\n\n /**\n * Emits a user logout event and optionally clears the current analytics user.\n *\n * @param data - optional additional event data\n * @param clearUser - whether to reset the analytics user identity; defaults to `true`\n */\n public sendUserLogoutEvent(data?: AnalyticsEventData, clearUser = true): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_LOGOUT_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.UserLogoutEvent\n );\n\n if (clearUser) {\n this.setUser(undefined);\n }\n }\n\n /**\n * Emits a user properties update event, used to sync user traits to analytics providers.\n *\n * @param user - the user whose properties are being updated\n * @param data - optional additional event data\n */\n public sendUserPropertiesEvent(user: AnalyticsUser, data?: AnalyticsEventData): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_PROPERTIES_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.UserPropertiesEvent,\n user\n );\n }\n\n /**\n * @deprecated When sending an event with no data, use {@link sendEventType} instead.\n */\n public sendEventData(name: AnalyticsEventName): void;\n /**\n * Sends a named analytics event with a data payload.\n *\n * This is the primary method for tracking custom events with associated properties.\n *\n * @param name - the event name (e.g., `'Interview Ended'`)\n * @param data - key-value data attached to the event\n *\n * @example\n * ```ts\n * analytics.sendEventData('Interview Ended', {\n * seconds: 120,\n * endedDueToTime: 'true'\n * });\n * ```\n */\n public sendEventData(name: AnalyticsEventName, data: AnalyticsEventData): void;\n public sendEventData(name: AnalyticsEventName, data?: AnalyticsEventData): void {\n return this.sendEvent({\n name,\n data\n });\n }\n\n /**\n * Sends a named event with no additional data, useful for simple occurrence tracking.\n *\n * @param eventType - the event name to track\n *\n * @example\n * ```ts\n * analytics.sendEventType('Finish Account Setup');\n * ```\n */\n public sendEventType(eventType: AnalyticsEventName): void {\n this.sendNextEvent(\n {\n name: eventType\n },\n DbxAnalyticsStreamEventType.Event\n );\n }\n\n /**\n * Sends a fully constructed analytics event object.\n *\n * @param event - the event containing name, optional value, and data\n */\n public sendEvent(event: AnalyticsEvent): void {\n this.sendNextEvent(event, DbxAnalyticsStreamEventType.Event);\n }\n\n /**\n * Sends a page view event, typically called on successful route transitions.\n *\n * @param page - optional page name/path override; if omitted, the provider determines the current page\n *\n * @example\n * ```ts\n * // In a router config function\n * transitionService.onSuccess({}, () => {\n * analyticsService.sendPageView();\n * });\n * ```\n */\n public sendPageView(page?: string): void {\n this.sendNextEvent(\n {\n name: page\n },\n DbxAnalyticsStreamEventType.PageView\n );\n }\n\n /**\n * Sends the next event.\n *\n * @param event\n * @param type\n * @param userOverride Uses this user if set as null or an override value. If undefined the current analytics user is used.\n */\n protected sendNextEvent(event: AnalyticsEvent = {}, type: DbxAnalyticsStreamEventType, userOverride?: Maybe<AnalyticsUser>): void {\n this.user$.pipe(first()).subscribe((analyticsUser) => {\n const user: Maybe<AnalyticsUser> = userOverride !== undefined ? userOverride : analyticsUser;\n const analyticsEvent: UserAnalyticsEvent = { ...event, user };\n this.nextEvent(analyticsEvent, type);\n });\n }\n\n protected nextEvent(event: UserAnalyticsEvent, type: DbxAnalyticsStreamEventType): void {\n const wrapper = dbxAnalyticsStreamEventAnalyticsEventWrapper(event, type);\n this._subject.next(wrapper);\n }\n\n // MARK: Internal\n private _init(): void {\n if (this._config.isProduction) {\n // Initialize listeners.\n this._config.listeners.forEach((listener) => {\n listener.listenToService(this);\n });\n } else {\n console.warn('AnalyticsService: Analytics not in production mode. All analytics events are ignored.');\n }\n\n if (this._config.logEvents || !this._config.isProduction) {\n console.log('AnalyticsService: Log analytics events enabled.');\n\n // Create a new subscription\n this._loggerSub.subscription = this._subject.subscribe((x) => {\n console.log(`AnalyticsService: Analytics Event - ${DbxAnalyticsStreamEventType[x.type]} | User: ${x.userId} | Data: ${JSON.stringify(x.event)}.`);\n });\n }\n\n this._userSourceSub.subscription = this.user$.subscribe((user) => {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.UserChange, user ?? null);\n });\n\n this._userIdEventSub.subscription = this.user$.pipe(distinctUntilChanged((a, b) => safeCompareEquality(a, b, (x, y) => x.user === y.user))).subscribe((user) => {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.UserIdChange, user ?? null);\n });\n }\n\n destroy() {\n this._subject.complete();\n this._userSource.complete();\n this._userSourceSub.destroy();\n this._userIdEventSub.destroy();\n this._loggerSub.destroy();\n }\n}\n","import { filterMaybe } from '@dereekb/rxjs';\nimport { switchMap, tap, shareReplay, merge, type Observable, of } from 'rxjs';\nimport { Directive, inject, input } from '@angular/core';\nimport { DbxActionContextStoreSourceInstance, cleanSubscriptionWithLockSet } from '@dereekb/dbx-core';\nimport { DbxAnalyticsService } from '../analytics/analytics.service';\nimport { type Maybe, type ReadableError } from '@dereekb/util';\nimport { toObservable } from '@angular/core/rxjs-interop';\n\n/**\n * Configuration for {@link DbxActionAnalyticsDirective} that maps action lifecycle events to analytics calls.\n *\n * Each callback receives the {@link DbxAnalyticsService} and relevant action data, allowing you to\n * send targeted analytics events at each stage of an action's lifecycle (trigger, ready, success, error).\n *\n * @example\n * ```ts\n * // In a component, define analytics config for a form submit action\n * readonly submitAnalytics: DbxActionAnalyticsConfig<MyFormValue, MyResult> = {\n * onReady: (service, value) => {\n * service.sendEventData('Form Submitted', { formType: 'onboard' });\n * },\n * onSuccess: (service, result, value) => {\n * service.sendEventType('Onboarding Complete');\n * },\n * onError: (service, error) => {\n * service.sendEventData('Form Submit Failed', { code: error?.code ?? 'unknown' });\n * }\n * };\n *\n * // In the template\n * // <button dbxAction [dbxActionAnalytics]=\"submitAnalytics\">Submit</button>\n * ```\n */\nexport interface DbxActionAnalyticsConfig<T = unknown, O = unknown> {\n /**\n * Called when the action is triggered (button pressed).\n */\n readonly onTriggered?: (service: DbxAnalyticsService) => void;\n /**\n * Called when the action value is ready and about to be processed.\n */\n readonly onReady?: (service: DbxAnalyticsService, value: T) => void;\n /**\n * Called when the action completes successfully.\n */\n readonly onSuccess?: (service: DbxAnalyticsService, result: Maybe<O>, value: T) => void;\n /**\n * Called when the action encounters an error.\n */\n readonly onError?: (service: DbxAnalyticsService, error: Maybe<ReadableError>) => void;\n}\n\n/**\n * Standalone directive that listens to a host {@link DbxActionDirective} and fires analytics events\n * based on the action's lifecycle (triggered, ready, success, error).\n *\n * Attach to any element that has a `dbxAction` directive and pass a {@link DbxActionAnalyticsConfig}\n * to define which events to send at each lifecycle stage.\n *\n * @example\n * ```html\n * <button dbxAction\n * [dbxActionHandler]=\"handleSave\"\n * [dbxActionAnalytics]=\"saveAnalytics\">\n * Save\n * </button>\n * ```\n */\n@Directive({\n selector: '[dbxActionAnalytics]',\n standalone: true\n})\nexport class DbxActionAnalyticsDirective<T, O> {\n readonly source = inject(DbxActionContextStoreSourceInstance<T, O>, { host: true });\n readonly analyticsService = inject(DbxAnalyticsService);\n\n readonly config = input<Maybe<DbxActionAnalyticsConfig<T, O>>>(undefined, { alias: 'dbxActionAnalytics' });\n readonly config$ = toObservable(this.config).pipe(filterMaybe(), shareReplay(1));\n\n constructor() {\n cleanSubscriptionWithLockSet({\n lockSet: this.source.lockSet,\n sub: this.config$\n .pipe(\n switchMap(({ onTriggered, onReady, onSuccess, onError }) => {\n const triggerObs: Observable<unknown>[] = [];\n\n if (onTriggered) {\n triggerObs.push(this.source.triggered$.pipe(tap(() => onTriggered(this.analyticsService))));\n }\n\n if (onReady) {\n triggerObs.push(this.source.valueReady$.pipe(tap((value) => onReady(this.analyticsService, value))));\n }\n\n if (onSuccess) {\n triggerObs.push(this.source.successPair$.pipe(tap(({ result, value }) => onSuccess(this.analyticsService, result, value))));\n }\n\n if (onError) {\n triggerObs.push(\n this.source.error$.pipe(\n filterMaybe(),\n tap((error) => onError(this.analyticsService, error))\n )\n );\n }\n\n return triggerObs.length ? merge(...triggerObs) : of();\n })\n )\n .subscribe()\n });\n }\n}\n","import { NgModule } from '@angular/core';\nimport { DbxActionAnalyticsDirective } from './analytics.action.directive';\n\n/**\n * @deprecated The exported DbxActionAnalyticsDirective is now a standalone component. Import that instead.\n */\n@NgModule({\n imports: [DbxActionAnalyticsDirective],\n exports: [DbxActionAnalyticsDirective]\n})\nexport class DbxAnalyticsActionModule {}\n","import { type EnvironmentProviders, Injector, type Provider, makeEnvironmentProviders } from '@angular/core';\nimport { DbxAnalyticsServiceConfiguration, DbxAnalyticsService } from './analytics.service';\n\n/**\n * Factory function that creates a {@link DbxAnalyticsServiceConfiguration} using the Angular injector.\n *\n * Used by {@link provideDbxAnalyticsService} to defer configuration resolution to runtime.\n */\nexport type DbxAnalyticsServiceConfigurationFactory = (injector: Injector) => DbxAnalyticsServiceConfiguration;\n\n/**\n * Configuration for {@link provideDbxAnalyticsService}.\n */\nexport interface ProvideDbxAnalyticsConfig {\n readonly dbxAnalyticsServiceConfigurationFactory: DbxAnalyticsServiceConfigurationFactory;\n}\n\n/**\n * Creates Angular environment providers that register {@link DbxAnalyticsService} and its configuration.\n *\n * Call this in your application's `providers` array to set up analytics with a custom configuration factory\n * that resolves listeners, user sources, and environment flags at runtime.\n *\n * @param config - contains the factory function that produces a {@link DbxAnalyticsServiceConfiguration}\n * @returns environment providers for the analytics service\n *\n * @example\n * ```ts\n * // In app.config.ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideDbxAnalyticsService({\n * dbxAnalyticsServiceConfigurationFactory: (injector: Injector) => ({\n * isProduction: environment.production,\n * logEvents: !environment.production,\n * listeners: [injector.get(DbxAnalyticsSegmentServiceListener)],\n * userSource: injector.get(DbxFirebaseAnalyticsUserSource)\n * })\n * })\n * ]\n * };\n * ```\n */\nexport function provideDbxAnalyticsService(config: ProvideDbxAnalyticsConfig): EnvironmentProviders {\n const { dbxAnalyticsServiceConfigurationFactory } = config;\n\n const providers: Provider[] = [\n // configuration\n {\n provide: DbxAnalyticsServiceConfiguration,\n useFactory: dbxAnalyticsServiceConfigurationFactory,\n deps: [Injector]\n },\n // service\n DbxAnalyticsService\n ];\n\n return makeEnvironmentProviders(providers);\n}\n","import { Injectable, InjectionToken, inject } from '@angular/core';\nimport { AbstractAsyncWindowLoadedService } from '@dereekb/browser';\nimport { poll } from '@dereekb/util';\n\n/**\n * Injection token for optionally preloading the Segment analytics script.\n */\nexport const PRELOAD_SEGMENT_TOKEN = new InjectionToken<string>('DbxAnalyticsSegmentApiServicePreload');\n\n/**\n * Configuration for the Segment analytics integration.\n *\n * @example\n * ```ts\n * const config = new DbxAnalyticsSegmentApiServiceConfig('your-segment-write-key');\n * config.active = environment.production;\n * config.logging = !environment.production;\n * ```\n */\nexport class DbxAnalyticsSegmentApiServiceConfig {\n writeKey: string;\n logging = true;\n active = true;\n constructor(writeKey: string) {\n this.writeKey = writeKey;\n }\n}\n\n/**\n * Extended Segment analytics type that includes the `invoked` flag set after the snippet initializes.\n */\ntype SegmentAnalyticsInvoked = SegmentAnalytics.AnalyticsJS & { invoked?: boolean };\n\n/**\n * Service that manages the async loading and initialization of the Segment analytics SDK from `window.analytics`.\n *\n * Polls for the Segment snippet to be invoked, then calls `analytics.load()` with the configured write key.\n * Once Segment reports ready, the resolved SDK instance is available via the inherited `service$` observable.\n *\n * Requires the Segment analytics snippet to be included in `index.html`.\n *\n * Provided via {@link provideDbxAnalyticsSegmentApiService}.\n *\n * @example\n * ```ts\n * // In app.config.ts\n * provideDbxAnalyticsSegmentApiService({\n * dbxAnalyticsSegmentApiServiceConfigFactory: (injector) => {\n * const config = new DbxAnalyticsSegmentApiServiceConfig(environment.analytics.segment);\n * config.active = environment.production;\n * return config;\n * }\n * })\n * ```\n */\n@Injectable()\nexport class DbxAnalyticsSegmentApiService extends AbstractAsyncWindowLoadedService<SegmentAnalytics.AnalyticsJS> {\n private readonly _config = inject(DbxAnalyticsSegmentApiServiceConfig);\n\n static readonly SEGMENT_API_WINDOW_KEY = 'analytics';\n static readonly SEGMENT_READY_KEY = 'SegmentReady';\n\n constructor() {\n const preload = inject(PRELOAD_SEGMENT_TOKEN, { optional: true });\n super(DbxAnalyticsSegmentApiService.SEGMENT_API_WINDOW_KEY, undefined, 'Segment', preload);\n }\n\n get config(): DbxAnalyticsSegmentApiServiceConfig {\n return this._config;\n }\n\n protected override _prepareCompleteLoadingService(): Promise<void> {\n return poll({\n // poll until analytics.invoked is true.\n check: () => Boolean((window.analytics as SegmentAnalyticsInvoked).invoked),\n timesToGiveup: 100\n });\n }\n\n protected override _initService(service: SegmentAnalytics.AnalyticsJS): Promise<SegmentAnalytics.AnalyticsJS> {\n return new Promise((resolve, reject) => {\n try {\n service.load(this._config.writeKey); // Initialize Segment\n\n // Wait for the service to ready itself.\n service.ready(() => {\n // Segment changes itself or rather the target, and the previous initial target is ignored after.\n const segment: SegmentAnalytics.AnalyticsJS = window[DbxAnalyticsSegmentApiService.SEGMENT_API_WINDOW_KEY];\n resolve(segment);\n });\n } catch (e) {\n console.log('Failed to init segment: ' + e);\n reject(e);\n }\n });\n }\n}\n","import { Injectable, inject } from '@angular/core';\nimport { type Maybe } from '@dereekb/util';\nimport { combineLatest } from 'rxjs';\nimport { AbstractDbxAnalyticsServiceListener, type DbxAnalyticsStreamEvent, DbxAnalyticsStreamEventType, type AnalyticsUser } from '../../analytics';\nimport { DbxAnalyticsSegmentApiService } from './segment.service';\n\n/**\n * Analytics listener that forwards {@link DbxAnalyticsStreamEvent} events to the Segment SDK.\n *\n * Automatically maps event types to the appropriate Segment methods:\n * - {@link DbxAnalyticsStreamEventType.Event} / {@link DbxAnalyticsStreamEventType.UserLoginEvent} -> `track()`\n * - {@link DbxAnalyticsStreamEventType.UserChange} / {@link DbxAnalyticsStreamEventType.NewUserEvent} -> `identify()`\n * - {@link DbxAnalyticsStreamEventType.UserLogoutEvent} -> `reset()`\n * - {@link DbxAnalyticsStreamEventType.PageView} -> `page()`\n *\n * Events are only sent when the Segment configuration is marked as `active`.\n * Provided at root level and registered as a listener via {@link DbxAnalyticsServiceConfiguration.listeners}.\n *\n * @example\n * ```ts\n * // Register in analytics configuration factory\n * function analyticsConfigFactory(injector: Injector): DbxAnalyticsServiceConfiguration {\n * const segmentListener = injector.get(DbxAnalyticsSegmentServiceListener);\n * return {\n * isProduction: true,\n * listeners: [segmentListener]\n * };\n * }\n * ```\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class DbxAnalyticsSegmentServiceListener extends AbstractDbxAnalyticsServiceListener {\n private readonly _segmentApi = inject(DbxAnalyticsSegmentApiService);\n\n constructor() {\n super();\n\n if (this._segmentApi.config.logging) {\n console.log('SegmentAnalyticsListenerService: Segment is logging events.');\n }\n\n if (!this._segmentApi.config.active) {\n console.log('SegmentAnalyticsListenerService: Segment is disabled from sending events to the server.');\n }\n }\n\n /**\n * Subscribes to the Segment API service and analytics event stream, forwarding events to the Segment SDK.\n *\n * Events are only sent when the Segment configuration is marked as active.\n *\n * @returns subscription to the combined Segment API and analytics event stream\n */\n protected _initializeServiceSubscription() {\n return combineLatest([this._segmentApi.service$, this.analyticsEvents$]).subscribe(([segment, streamEvent]: [SegmentAnalytics.AnalyticsJS, DbxAnalyticsStreamEvent]) => {\n if (this._segmentApi.config.logging) {\n console.log('Segment Listener Logging Event: ', streamEvent);\n }\n\n if (this._segmentApi.config.active) {\n this.handleStreamEvent(segment, streamEvent);\n }\n });\n }\n\n /**\n * Routes an analytics stream event to the appropriate Segment API method based on event type.\n *\n * @param api - The Segment analytics SDK instance\n * @param streamEvent - The analytics event to process\n */\n protected handleStreamEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent): void {\n switch (streamEvent.type) {\n case DbxAnalyticsStreamEventType.NewUserEvent:\n this.updateWithNewUserEvent(api, streamEvent);\n break;\n case DbxAnalyticsStreamEventType.UserLoginEvent:\n this.changeUser(api, streamEvent.user);\n this.updateWithEvent(api, streamEvent);\n break;\n case DbxAnalyticsStreamEventType.Event:\n this.updateWithEvent(api, streamEvent);\n break;\n case DbxAnalyticsStreamEventType.UserLogoutEvent:\n this.changeUser(api, undefined);\n break;\n case DbxAnalyticsStreamEventType.PageView:\n api.page();\n break;\n case DbxAnalyticsStreamEventType.UserChange:\n this.changeUser(api, streamEvent.user);\n break;\n case DbxAnalyticsStreamEventType.UserIdChange:\n case DbxAnalyticsStreamEventType.UserPropertiesEvent:\n // These event types are not forwarded to Segment\n break;\n }\n }\n\n /**\n * Handles a new user registration event by identifying the user in Segment.\n *\n * @param api - The Segment analytics SDK instance\n * @param streamEvent - The event containing the new user data\n */\n protected updateWithNewUserEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent): void {\n this.changeUser(api, streamEvent.user);\n }\n\n /**\n * Sends a track event to Segment with the event name, value, and additional data properties.\n *\n * @param api - The Segment analytics SDK instance\n * @param streamEvent - The analytics event containing name, value, and data\n * @param name - Optional override for the event name\n */\n protected updateWithEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent, name?: string): void {\n const event = streamEvent.event;\n const eventName = name || event?.name;\n\n if (eventName) {\n const value = event?.value;\n const data = event?.data;\n\n api.track(\n eventName,\n {\n ...(value != null\n ? {\n value\n }\n : undefined),\n ...data\n },\n {},\n () => {\n if (this._segmentApi.config.logging) {\n console.log('Segment track success.');\n }\n }\n );\n }\n }\n\n private changeUser(api: SegmentAnalytics.AnalyticsJS, user: Maybe<AnalyticsUser>): void {\n if (user?.user) {\n api.identify(\n user.user,\n {\n ...user.properties\n },\n {},\n () => {\n if (this._segmentApi.config.logging) {\n console.log('Segment identify success.');\n }\n }\n );\n } else {\n api.reset();\n }\n }\n}\n","import { type EnvironmentProviders, Injector, makeEnvironmentProviders, type Provider } from '@angular/core';\nimport { DbxAnalyticsSegmentApiService, DbxAnalyticsSegmentApiServiceConfig, PRELOAD_SEGMENT_TOKEN } from './segment.service';\n\n/**\n * Factory function that creates a {@link DbxAnalyticsSegmentApiServiceConfig} using the Angular injector.\n *\n * Used by {@link provideDbxAnalyticsSegmentApiService} to defer Segment configuration to runtime.\n */\nexport type DbxAnalyticsSegmentApiServiceConfigFactory = (injector: Injector) => DbxAnalyticsSegmentApiServiceConfig;\n\n/**\n * Configuration for {@link provideDbxAnalyticsSegmentApiService}.\n */\nexport interface ProvideDbxAnalyticsSegmentModuleConfig {\n /**\n * Whether to preload the Segment script token.\n */\n readonly preloadSegmentToken?: boolean;\n /**\n * Factory function that produces the Segment API service configuration.\n */\n readonly dbxAnalyticsSegmentApiServiceConfigFactory: DbxAnalyticsSegmentApiServiceConfigFactory;\n}\n\n/**\n * Creates Angular environment providers that register {@link DbxAnalyticsSegmentApiService} for Segment analytics integration.\n *\n * Use alongside {@link provideDbxAnalyticsService} to wire Segment as an analytics listener.\n *\n * @param config - Segment-specific configuration including the write key factory\n * @returns environment providers for Segment analytics\n *\n * @example\n * ```ts\n * // In app.config.ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideDbxAnalyticsSegmentApiService({\n * dbxAnalyticsSegmentApiServiceConfigFactory: (injector) => {\n * const config = new DbxAnalyticsSegmentApiServiceConfig(environment.analytics.segment);\n * config.active = environment.production;\n * config.logging = !environment.production;\n * return config;\n * }\n * }),\n * provideDbxAnalyticsService({\n * dbxAnalyticsServiceConfigurationFactory: (injector) => ({\n * isProduction: environment.production,\n * listeners: [injector.get(DbxAnalyticsSegmentServiceListener)]\n * })\n * })\n * ]\n * };\n * ```\n */\nexport function provideDbxAnalyticsSegmentApiService(config: ProvideDbxAnalyticsSegmentModuleConfig): EnvironmentProviders {\n const { preloadSegmentToken, dbxAnalyticsSegmentApiServiceConfigFactory } = config;\n\n const providers: Provider[] = [\n // configuration\n {\n provide: DbxAnalyticsSegmentApiServiceConfig,\n useFactory: dbxAnalyticsSegmentApiServiceConfigFactory,\n deps: [Injector]\n },\n // service\n DbxAnalyticsSegmentApiService\n ];\n\n if (preloadSegmentToken) {\n providers.push({\n provide: PRELOAD_SEGMENT_TOKEN,\n useValue: preloadSegmentToken\n });\n }\n\n return makeEnvironmentProviders(providers);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAGA;;;;;AAKG;IACS;AAAZ,CAAA,UAAY,2BAA2B,EAAA;AACrC;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,UAAA,CAAA,GAAA,CAAA,CAAA,GAAA,UAAQ;AACR;;;;AAIG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU;AACV;;;;AAIG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,cAAA,CAAA,GAAA,CAAA,CAAA,GAAA,cAAY;;AAGZ;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,cAAA,CAAA,GAAA,CAAA,CAAA,GAAA,cAAY;AACZ;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,gBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,gBAAc;AACd;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,iBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,iBAAe;AACf;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,qBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,qBAAmB;;AAGnB;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK;A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cAFjC,MAAM,EAAA,CAAA;;4FAEP,kCAAkC,EAAA,UAAA,EAAA,CAAA;kBAH9C,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACRD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACG,SAAU,oCAAoC,CAAC,MAA8C,EAAA;AACjG,IAAA,MAAM,EAAE,mBAAmB,EAAE,0CAA0C,EAAE,GAAG,MAAM;AAElF,IAAA,MAAM,SAAS,GAAe;;AAE5B,QAAA;AACE,YAAA,OAAO,EAAE,mCAAmC;AAC5C,YAAA,UAAU,EAAE,0CAA0C;YACtD,IAAI,EAAE,CAAC,QAAQ;AAChB,SAAA;;QAED;KACD;IAED,IAAI,mBAAmB,EAAE;QACvB,SAAS,CAAC,IAAI,CAAC;AACb,YAAA,OAAO,EAAE,qBAAqB;AAC9B,YAAA,QAAQ,EAAE;AACX,SAAA,CAAC;IACJ;AAEA,IAAA,OAAO,wBAAwB,CAAC,SAAS,CAAC;AAC5C;;AC7EA;;AAEG;;;;"}
1
+ {"version":3,"file":"dereekb-dbx-analytics.mjs","sources":["../../../../packages/dbx-analytics/src/lib/analytics/analytics.stream.ts","../../../../packages/dbx-analytics/src/lib/analytics/analytics.service.ts","../../../../packages/dbx-analytics/src/lib/action/analytics.action.directive.ts","../../../../packages/dbx-analytics/src/lib/action/analytics.module.ts","../../../../packages/dbx-analytics/src/lib/analytics/analytics.providers.ts","../../../../packages/dbx-analytics/src/lib/providers/mixpanel/mixpanel.service.ts","../../../../packages/dbx-analytics/src/lib/providers/mixpanel/mixpanel.listener.service.ts","../../../../packages/dbx-analytics/src/lib/providers/mixpanel/mixpanel.providers.ts","../../../../packages/dbx-analytics/src/lib/providers/segment/segment.service.ts","../../../../packages/dbx-analytics/src/lib/providers/segment/segment.listener.service.ts","../../../../packages/dbx-analytics/src/lib/providers/segment/segment.providers.ts","../../../../packages/dbx-analytics/src/dereekb-dbx-analytics.ts"],"sourcesContent":["import { type Maybe } from '@dereekb/util';\nimport { type AnalyticsUser, type UserAnalyticsEvent, type AnalyticsUserId } from './analytics';\n\n/**\n * Categorizes the kind of analytics stream event emitted by {@link DbxAnalyticsService}.\n *\n * Listeners use this type to route events to the appropriate analytics provider method\n * (e.g., Segment `track()`, `identify()`, `page()`).\n */\nexport enum DbxAnalyticsStreamEventType {\n /**\n * A page/screen view event, typically sent on route transitions.\n */\n PageView,\n /**\n * Emitted any time the user value changes, including when transitioning from defined to undefined.\n *\n * Used by listeners to update the identified user in analytics providers.\n */\n UserChange,\n /**\n * Emitted only when the user's unique ID changes, filtering out property-only updates.\n *\n * Useful for triggering identity calls without redundant updates when only traits change.\n */\n UserIdChange,\n\n // User Events\n /**\n * A new user registration event.\n */\n NewUserEvent,\n /**\n * A returning user login event.\n */\n UserLoginEvent,\n /**\n * A user logout event.\n */\n UserLogoutEvent,\n /**\n * An update to user profile properties/traits.\n */\n UserPropertiesEvent,\n\n // Events\n /**\n * A generic custom analytics event.\n */\n Event,\n\n // Session Replay\n /**\n * Request to start session replay recording.\n */\n StartSessionRecording,\n /**\n * Request to stop session replay recording.\n */\n StopSessionRecording,\n /**\n * Request to pause an active session replay recording without clearing it.\n */\n PauseSessionRecording,\n /**\n * Request to resume a previously paused session replay recording.\n */\n ResumeSessionRecording\n}\n\n/**\n * Represents a single event in the analytics stream, combining the event type, payload, and user context.\n *\n * Emitted by {@link DbxAnalyticsService} and consumed by {@link DbxAnalyticsServiceListener} implementations\n * (e.g., {@link DbxAnalyticsSegmentServiceListener}) to forward events to external analytics providers.\n *\n * @example\n * ```ts\n * // Subscribe to the analytics event stream\n * analyticsService.events$.subscribe((streamEvent: DbxAnalyticsStreamEvent) => {\n * console.log(streamEvent.type, streamEvent.event?.name, streamEvent.userId);\n * });\n * ```\n */\nexport interface DbxAnalyticsStreamEvent {\n readonly type: DbxAnalyticsStreamEventType;\n readonly user?: Maybe<AnalyticsUser>;\n readonly event?: UserAnalyticsEvent;\n readonly userId?: AnalyticsUserId;\n}\n","import { type Observable, Subject, BehaviorSubject, of, type Subscription, first, shareReplay, switchMap, distinctUntilChanged } from 'rxjs';\nimport { Injectable, inject } from '@angular/core';\nimport { SubscriptionObject, filterMaybe } from '@dereekb/rxjs';\nimport { type AnalyticsEvent, type AnalyticsEventData, type AnalyticsEventName, type AnalyticsUser, type NewUserAnalyticsEventData, type UserAnalyticsEvent } from './analytics';\nimport { type DbxAnalyticsStreamEvent, DbxAnalyticsStreamEventType } from './analytics.stream';\nimport { type Maybe, type Destroyable, safeCompareEquality } from '@dereekb/util';\n\n/**\n * Abstract emitter interface for sending analytics events.\n *\n * Implemented by {@link DbxAnalyticsService} as the primary concrete implementation.\n * Components and services use this to fire analytics events without coupling to a specific provider.\n *\n * @example\n * ```ts\n * // Inject and send a custom event\n * const emitter = inject(DbxAnalyticsEventEmitterService);\n * emitter.sendEventData('Button Clicked', { buttonId: 'save' });\n * ```\n */\nexport abstract class DbxAnalyticsEventEmitterService {\n abstract sendNewUserEvent(user: AnalyticsUser, data: NewUserAnalyticsEventData): void;\n abstract sendUserLoginEvent(user: AnalyticsUser, data?: AnalyticsEventData): void;\n abstract sendUserLogoutEvent(data?: AnalyticsEventData): void;\n abstract sendUserPropertiesEvent(user: AnalyticsUser, data?: AnalyticsEventData): void;\n /**\n * @deprecated When sending an event with no data, use {@link sendEventType} instead.\n */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n abstract sendEventData(name: AnalyticsEventName): void;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n abstract sendEventData(name: AnalyticsEventName, data: AnalyticsEventData): void;\n abstract sendEvent(event: AnalyticsEvent): void;\n abstract sendPageView(page?: string): void;\n abstract startSessionRecording(): void;\n abstract stopSessionRecording(): void;\n abstract pauseSessionRecording(): void;\n abstract resumeSessionRecording(): void;\n}\n\n/**\n * Abstract interface exposing the analytics event stream as an observable.\n *\n * Implemented by {@link DbxAnalyticsService}. Listeners subscribe to `events$` to forward events to external providers.\n */\nexport abstract class DbxAnalyticsEventStreamService {\n abstract readonly events$: Observable<DbxAnalyticsStreamEvent>;\n}\n\n/**\n * Abstract source for the current analytics user identity.\n *\n * Provide an implementation to automatically associate a user with all emitted analytics events.\n * Typically backed by the auth system (e.g., {@link DbxFirebaseAnalyticsUserSource}).\n *\n * @example\n * ```ts\n * // Provide a static user source\n * const userSource: DbxAnalyticsUserSource = {\n * analyticsUser$: of({ user: 'uid_abc123', properties: { role: 'admin' } })\n * };\n * ```\n */\nexport abstract class DbxAnalyticsUserSource {\n abstract readonly analyticsUser$: Observable<Maybe<AnalyticsUser>>;\n}\n\n/**\n * Abstract listener that receives analytics events from {@link DbxAnalyticsService}.\n *\n * Implement this to forward events to an external analytics provider (e.g., Segment, Mixpanel).\n * Register listeners via {@link DbxAnalyticsServiceConfiguration.listeners}.\n */\nexport abstract class DbxAnalyticsServiceListener {\n public abstract listenToService(service: DbxAnalyticsService): void;\n}\n\n/**\n * Base class for analytics service listeners that manages subscription lifecycle and provides\n * reactive access to the analytics service and its event stream.\n *\n * Subclasses implement {@link _initializeServiceSubscription} to subscribe to events and forward them\n * to an external analytics provider.\n *\n * @example\n * ```ts\n * class MyAnalyticsListener extends AbstractDbxAnalyticsServiceListener {\n * protected _initializeServiceSubscription(): Subscription | false {\n * return this.analyticsEvents$.subscribe((event) => {\n * console.log('Event:', event.type, event.event?.name);\n * });\n * }\n * }\n * ```\n */\nexport abstract class AbstractDbxAnalyticsServiceListener implements DbxAnalyticsServiceListener, Destroyable {\n private _sub = new SubscriptionObject();\n protected _analytics = new BehaviorSubject<Maybe<DbxAnalyticsService>>(undefined);\n\n readonly analytics$ = this._analytics.pipe(filterMaybe(), shareReplay(1));\n readonly analyticsEvents$ = this.analytics$.pipe(\n switchMap((x) => x.events$),\n shareReplay(1)\n );\n\n // MARK: AnalyticsServiceListener\n listenToService(service: DbxAnalyticsService): void {\n this._analytics.next(service);\n const sub = this._initializeServiceSubscription();\n\n if (sub !== false) {\n this._sub.subscription = sub;\n }\n }\n\n protected abstract _initializeServiceSubscription(): Subscription | false;\n\n // MARK: Destroy\n destroy(): void {\n this._analytics.complete();\n this._sub.destroy();\n }\n}\n\n/**\n * Configuration for {@link DbxAnalyticsService}, controlling which listeners receive events,\n * whether analytics runs in production mode, and optionally providing a user source.\n *\n * In non-production mode, listeners are not initialized and all events are logged to the console instead.\n * Provide via {@link provideDbxAnalyticsService} using a factory function.\n *\n * @example\n * ```ts\n * const config: DbxAnalyticsServiceConfiguration = {\n * isProduction: environment.production,\n * logEvents: !environment.production,\n * listeners: [segmentListener],\n * userSource: firebaseAnalyticsUserSource\n * };\n * ```\n */\nexport abstract class DbxAnalyticsServiceConfiguration {\n readonly listeners: DbxAnalyticsServiceListener[] = [];\n readonly isProduction?: boolean;\n readonly logEvents?: boolean;\n readonly userSource?: DbxAnalyticsUserSource;\n}\n\n/**\n * A fully resolved analytics stream event that includes the event payload, type, user context, and extracted user ID.\n *\n * Created by {@link dbxAnalyticsStreamEventAnalyticsEventWrapper} and emitted through the analytics event stream.\n */\nexport interface DbxAnalyticsStreamEventAnalyticsEventWrapper extends DbxAnalyticsStreamEvent {\n readonly event: UserAnalyticsEvent;\n readonly type: DbxAnalyticsStreamEventType;\n readonly user: Maybe<AnalyticsUser>;\n readonly userId: string | undefined;\n}\n\n/**\n * Wraps a {@link UserAnalyticsEvent} into a {@link DbxAnalyticsStreamEventAnalyticsEventWrapper},\n * extracting the user ID for convenient access by listeners.\n *\n * @param event - the analytics event with optional user context\n * @param type - the stream event type classification; defaults to `Event`\n * @returns a wrapper combining the event, type, user, and extracted userId\n *\n * @example\n * ```ts\n * const wrapper = dbxAnalyticsStreamEventAnalyticsEventWrapper(\n * { name: 'Button Clicked', user: { user: 'uid_123' } },\n * DbxAnalyticsStreamEventType.Event\n * );\n * // wrapper.userId === 'uid_123'\n * ```\n */\nexport function dbxAnalyticsStreamEventAnalyticsEventWrapper(event: UserAnalyticsEvent, type: DbxAnalyticsStreamEventType = DbxAnalyticsStreamEventType.Event) {\n const { user } = event;\n const userId = user ? user.user : undefined;\n\n return {\n event,\n type,\n user,\n userId\n };\n}\n\n/**\n * Central analytics service that emits typed analytics events for consumption by registered listeners.\n *\n * Acts as both the event emitter (components call methods like {@link sendEventData}, {@link sendPageView})\n * and the event stream source (listeners subscribe to {@link events$}).\n *\n * In production mode, registered {@link DbxAnalyticsServiceListener} instances (e.g., Segment) receive all events.\n * In non-production mode, events are logged to the console for debugging.\n *\n * Provided via {@link provideDbxAnalyticsService} with a {@link DbxAnalyticsServiceConfiguration} factory.\n *\n * @example\n * ```ts\n * // Send a custom event from a component\n * const analytics = inject(DbxAnalyticsService);\n * analytics.sendEventData('Interview Started', { candidateId: 'abc123' });\n *\n * // Send a page view on route transitions\n * transitionService.onSuccess({}, () => {\n * analytics.sendPageView();\n * });\n * ```\n */\n@Injectable()\nexport class DbxAnalyticsService implements DbxAnalyticsEventStreamService, DbxAnalyticsEventEmitterService, Destroyable {\n private readonly _config = inject(DbxAnalyticsServiceConfiguration);\n\n // TODO: Make these configurable.\n static readonly USER_REGISTRATION_EVENT_NAME = 'User Registered';\n static readonly USER_LOGIN_EVENT_NAME = 'User Login';\n static readonly USER_LOGOUT_EVENT_NAME = 'User Logout';\n static readonly USER_PROPERTIES_EVENT_NAME = 'User Properties';\n\n private _subject = new Subject<DbxAnalyticsStreamEvent>();\n readonly events$ = this._subject.asObservable();\n\n private _userSource = new BehaviorSubject<Maybe<DbxAnalyticsUserSource>>(undefined);\n\n readonly user$ = this._userSource.pipe(\n switchMap((x) => (x ? x.analyticsUser$ : of(undefined))),\n shareReplay(1)\n );\n\n private _userSourceSub = new SubscriptionObject();\n private _userIdEventSub = new SubscriptionObject();\n private _loggerSub = new SubscriptionObject();\n\n constructor() {\n this._init();\n let userSource: Maybe<DbxAnalyticsUserSource> = inject(DbxAnalyticsUserSource, { optional: true });\n userSource = userSource || this._config.userSource;\n\n if (userSource) {\n this.setUserSource(userSource);\n }\n }\n\n // MARK: Source\n /**\n * Sets the analytics user directly, overriding any configured {@link DbxAnalyticsUserSource}.\n *\n * Pass `undefined` to clear the current user (e.g., on logout).\n *\n * @param user - the user to identify, or undefined to clear\n */\n public setUser(user: Maybe<AnalyticsUser>): void {\n let source: Maybe<DbxAnalyticsUserSource>;\n\n if (user) {\n source = { analyticsUser$: of(user) };\n }\n\n this._userSource.next(source);\n\n if (this._userSource.value) {\n console.warn('DbxAnalyticsService has a userSource that is set. Source is now overridden by setUser() value.');\n }\n }\n\n /**\n * Sets the reactive user source that automatically updates the analytics user as auth state changes.\n *\n * @param source - the user source providing an observable of the current analytics user\n */\n public setUserSource(source: DbxAnalyticsUserSource): void {\n this._userSource.next(source);\n }\n\n // MARK: DbxAnalyticsEventEmitterService\n /**\n * Emits a new user registration event, typically sent once after account creation.\n *\n * @param user - the newly registered user\n * @param data - registration-specific data including the signup method\n */\n public sendNewUserEvent(user: AnalyticsUser, data: NewUserAnalyticsEventData): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_REGISTRATION_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.NewUserEvent,\n user\n );\n }\n\n /**\n * Emits a user login event, identifying the user in analytics providers.\n *\n * @param user - the user who logged in\n * @param data - optional additional event data\n */\n public sendUserLoginEvent(user: AnalyticsUser, data?: AnalyticsEventData): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_LOGIN_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.UserLoginEvent,\n user\n );\n }\n\n /**\n * Emits a user logout event and optionally clears the current analytics user.\n *\n * @param data - optional additional event data\n * @param clearUser - whether to reset the analytics user identity; defaults to `true`\n */\n public sendUserLogoutEvent(data?: AnalyticsEventData, clearUser = true): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_LOGOUT_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.UserLogoutEvent\n );\n\n if (clearUser) {\n this.setUser(undefined);\n }\n }\n\n /**\n * Emits a user properties update event, used to sync user traits to analytics providers.\n *\n * @param user - the user whose properties are being updated\n * @param data - optional additional event data\n */\n public sendUserPropertiesEvent(user: AnalyticsUser, data?: AnalyticsEventData): void {\n this.sendNextEvent(\n {\n name: DbxAnalyticsService.USER_PROPERTIES_EVENT_NAME,\n data\n },\n DbxAnalyticsStreamEventType.UserPropertiesEvent,\n user\n );\n }\n\n /**\n * @deprecated When sending an event with no data, use {@link sendEventType} instead.\n */\n public sendEventData(name: AnalyticsEventName): void;\n /**\n * Sends a named analytics event with a data payload.\n *\n * This is the primary method for tracking custom events with associated properties.\n *\n * @param name - the event name (e.g., `'Interview Ended'`)\n * @param data - key-value data attached to the event\n *\n * @example\n * ```ts\n * analytics.sendEventData('Interview Ended', {\n * seconds: 120,\n * endedDueToTime: 'true'\n * });\n * ```\n */\n public sendEventData(name: AnalyticsEventName, data: AnalyticsEventData): void;\n public sendEventData(name: AnalyticsEventName, data?: AnalyticsEventData): void {\n return this.sendEvent({\n name,\n data\n });\n }\n\n /**\n * Sends a named event with no additional data, useful for simple occurrence tracking.\n *\n * @param eventType - the event name to track\n *\n * @example\n * ```ts\n * analytics.sendEventType('Finish Account Setup');\n * ```\n */\n public sendEventType(eventType: AnalyticsEventName): void {\n this.sendNextEvent(\n {\n name: eventType\n },\n DbxAnalyticsStreamEventType.Event\n );\n }\n\n /**\n * Sends a fully constructed analytics event object.\n *\n * @param event - the event containing name, optional value, and data\n */\n public sendEvent(event: AnalyticsEvent): void {\n this.sendNextEvent(event, DbxAnalyticsStreamEventType.Event);\n }\n\n /**\n * Sends a page view event, typically called on successful route transitions.\n *\n * @param page - optional page name/path override; if omitted, the provider determines the current page\n *\n * @example\n * ```ts\n * // In a router config function\n * transitionService.onSuccess({}, () => {\n * analyticsService.sendPageView();\n * });\n * ```\n */\n public sendPageView(page?: string): void {\n this.sendNextEvent(\n {\n name: page\n },\n DbxAnalyticsStreamEventType.PageView\n );\n }\n\n /**\n * Requests that opt-in listeners (e.g. Mixpanel) start session replay recording.\n *\n * Forwarded as a {@link DbxAnalyticsStreamEventType.StartSessionRecording} event. Listeners\n * that don't handle session replay (e.g. Segment) ignore it.\n */\n public startSessionRecording(): void {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.StartSessionRecording);\n }\n\n /**\n * Requests that opt-in listeners stop session replay recording.\n *\n * Forwarded as a {@link DbxAnalyticsStreamEventType.StopSessionRecording} event.\n */\n public stopSessionRecording(): void {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.StopSessionRecording);\n }\n\n /**\n * Requests that opt-in listeners pause active session replay recording without clearing it.\n *\n * Forwarded as a {@link DbxAnalyticsStreamEventType.PauseSessionRecording} event.\n */\n public pauseSessionRecording(): void {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.PauseSessionRecording);\n }\n\n /**\n * Requests that opt-in listeners resume previously paused session replay recording.\n *\n * Forwarded as a {@link DbxAnalyticsStreamEventType.ResumeSessionRecording} event.\n */\n public resumeSessionRecording(): void {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.ResumeSessionRecording);\n }\n\n /**\n * Sends the next event.\n *\n * @param event\n * @param type\n * @param userOverride Uses this user if set as null or an override value. If undefined the current analytics user is used.\n */\n protected sendNextEvent(event: AnalyticsEvent = {}, type: DbxAnalyticsStreamEventType, userOverride?: Maybe<AnalyticsUser>): void {\n this.user$.pipe(first()).subscribe((analyticsUser) => {\n const user: Maybe<AnalyticsUser> = userOverride !== undefined ? userOverride : analyticsUser;\n const analyticsEvent: UserAnalyticsEvent = { ...event, user };\n this.nextEvent(analyticsEvent, type);\n });\n }\n\n protected nextEvent(event: UserAnalyticsEvent, type: DbxAnalyticsStreamEventType): void {\n const wrapper = dbxAnalyticsStreamEventAnalyticsEventWrapper(event, type);\n this._subject.next(wrapper);\n }\n\n // MARK: Internal\n private _init(): void {\n if (this._config.isProduction) {\n // Initialize listeners.\n this._config.listeners.forEach((listener) => {\n listener.listenToService(this);\n });\n } else {\n console.warn('AnalyticsService: Analytics not in production mode. All analytics events are ignored.');\n }\n\n if (this._config.logEvents || !this._config.isProduction) {\n console.log('AnalyticsService: Log analytics events enabled.');\n\n // Create a new subscription\n this._loggerSub.subscription = this._subject.subscribe((x) => {\n console.log(`AnalyticsService: Analytics Event - ${DbxAnalyticsStreamEventType[x.type]} | User: ${x.userId} | Data: ${JSON.stringify(x.event)}.`);\n });\n }\n\n this._userSourceSub.subscription = this.user$.subscribe((user) => {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.UserChange, user ?? null);\n });\n\n this._userIdEventSub.subscription = this.user$.pipe(distinctUntilChanged((a, b) => safeCompareEquality(a, b, (x, y) => x.user === y.user))).subscribe((user) => {\n this.sendNextEvent({}, DbxAnalyticsStreamEventType.UserIdChange, user ?? null);\n });\n }\n\n destroy() {\n this._subject.complete();\n this._userSource.complete();\n this._userSourceSub.destroy();\n this._userIdEventSub.destroy();\n this._loggerSub.destroy();\n }\n}\n","import { filterMaybe } from '@dereekb/rxjs';\nimport { switchMap, tap, shareReplay, merge, type Observable, of } from 'rxjs';\nimport { Directive, inject, input } from '@angular/core';\nimport { DbxActionContextStoreSourceInstance, cleanSubscriptionWithLockSet } from '@dereekb/dbx-core';\nimport { DbxAnalyticsService } from '../analytics/analytics.service';\nimport { type Maybe, type ReadableError } from '@dereekb/util';\nimport { toObservable } from '@angular/core/rxjs-interop';\n\n/**\n * Configuration for {@link DbxActionAnalyticsDirective} that maps action lifecycle events to analytics calls.\n *\n * Each callback receives the {@link DbxAnalyticsService} and relevant action data, allowing you to\n * send targeted analytics events at each stage of an action's lifecycle (trigger, ready, success, error).\n *\n * @example\n * ```ts\n * // In a component, define analytics config for a form submit action\n * readonly submitAnalytics: DbxActionAnalyticsConfig<MyFormValue, MyResult> = {\n * onReady: (service, value) => {\n * service.sendEventData('Form Submitted', { formType: 'onboard' });\n * },\n * onSuccess: (service, result, value) => {\n * service.sendEventType('Onboarding Complete');\n * },\n * onError: (service, error) => {\n * service.sendEventData('Form Submit Failed', { code: error?.code ?? 'unknown' });\n * }\n * };\n *\n * // In the template\n * // <button dbxAction [dbxActionAnalytics]=\"submitAnalytics\">Submit</button>\n * ```\n */\nexport interface DbxActionAnalyticsConfig<T = unknown, O = unknown> {\n /**\n * Called when the action is triggered (button pressed).\n */\n readonly onTriggered?: (service: DbxAnalyticsService) => void;\n /**\n * Called when the action value is ready and about to be processed.\n */\n readonly onReady?: (service: DbxAnalyticsService, value: T) => void;\n /**\n * Called when the action completes successfully.\n */\n readonly onSuccess?: (service: DbxAnalyticsService, result: Maybe<O>, value: T) => void;\n /**\n * Called when the action encounters an error.\n */\n readonly onError?: (service: DbxAnalyticsService, error: Maybe<ReadableError>) => void;\n}\n\n/**\n * Standalone directive that listens to a host {@link DbxActionDirective} and fires analytics events\n * based on the action's lifecycle (triggered, ready, success, error).\n *\n * Attach to any element that has a `dbxAction` directive and pass a {@link DbxActionAnalyticsConfig}\n * to define which events to send at each lifecycle stage.\n *\n * @example\n * ```html\n * <button dbxAction\n * [dbxActionHandler]=\"handleSave\"\n * [dbxActionAnalytics]=\"saveAnalytics\">\n * Save\n * </button>\n * ```\n */\n@Directive({\n selector: '[dbxActionAnalytics]',\n standalone: true\n})\nexport class DbxActionAnalyticsDirective<T, O> {\n readonly source = inject(DbxActionContextStoreSourceInstance<T, O>, { host: true });\n readonly analyticsService = inject(DbxAnalyticsService);\n\n readonly config = input<Maybe<DbxActionAnalyticsConfig<T, O>>>(undefined, { alias: 'dbxActionAnalytics' });\n readonly config$ = toObservable(this.config).pipe(filterMaybe(), shareReplay(1));\n\n constructor() {\n cleanSubscriptionWithLockSet({\n lockSet: this.source.lockSet,\n sub: this.config$\n .pipe(\n switchMap(({ onTriggered, onReady, onSuccess, onError }) => {\n const triggerObs: Observable<unknown>[] = [];\n\n if (onTriggered) {\n triggerObs.push(this.source.triggered$.pipe(tap(() => onTriggered(this.analyticsService))));\n }\n\n if (onReady) {\n triggerObs.push(this.source.valueReady$.pipe(tap((value) => onReady(this.analyticsService, value))));\n }\n\n if (onSuccess) {\n triggerObs.push(this.source.successPair$.pipe(tap(({ result, value }) => onSuccess(this.analyticsService, result, value))));\n }\n\n if (onError) {\n triggerObs.push(\n this.source.error$.pipe(\n filterMaybe(),\n tap((error) => onError(this.analyticsService, error))\n )\n );\n }\n\n return triggerObs.length ? merge(...triggerObs) : of();\n })\n )\n .subscribe()\n });\n }\n}\n","import { NgModule } from '@angular/core';\nimport { DbxActionAnalyticsDirective } from './analytics.action.directive';\n\n/**\n * @deprecated The exported DbxActionAnalyticsDirective is now a standalone component. Import that instead.\n */\n@NgModule({\n imports: [DbxActionAnalyticsDirective],\n exports: [DbxActionAnalyticsDirective]\n})\nexport class DbxAnalyticsActionModule {}\n","import { type EnvironmentProviders, Injector, type Provider, makeEnvironmentProviders } from '@angular/core';\nimport { DbxAnalyticsServiceConfiguration, DbxAnalyticsService } from './analytics.service';\n\n/**\n * Factory function that creates a {@link DbxAnalyticsServiceConfiguration} using the Angular injector.\n *\n * Used by {@link provideDbxAnalyticsService} to defer configuration resolution to runtime.\n */\nexport type DbxAnalyticsServiceConfigurationFactory = (injector: Injector) => DbxAnalyticsServiceConfiguration;\n\n/**\n * Configuration for {@link provideDbxAnalyticsService}.\n */\nexport interface ProvideDbxAnalyticsConfig {\n readonly dbxAnalyticsServiceConfigurationFactory: DbxAnalyticsServiceConfigurationFactory;\n}\n\n/**\n * Creates Angular environment providers that register {@link DbxAnalyticsService} and its configuration.\n *\n * Call this in your application's `providers` array to set up analytics with a custom configuration factory\n * that resolves listeners, user sources, and environment flags at runtime.\n *\n * @param config - contains the factory function that produces a {@link DbxAnalyticsServiceConfiguration}\n * @returns environment providers for the analytics service\n *\n * @example\n * ```ts\n * // In app.config.ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideDbxAnalyticsService({\n * dbxAnalyticsServiceConfigurationFactory: (injector: Injector) => ({\n * isProduction: environment.production,\n * logEvents: !environment.production,\n * listeners: [injector.get(DbxAnalyticsSegmentServiceListener)],\n * userSource: injector.get(DbxFirebaseAnalyticsUserSource)\n * })\n * })\n * ]\n * };\n * ```\n */\nexport function provideDbxAnalyticsService(config: ProvideDbxAnalyticsConfig): EnvironmentProviders {\n const { dbxAnalyticsServiceConfigurationFactory } = config;\n\n const providers: Provider[] = [\n // configuration\n {\n provide: DbxAnalyticsServiceConfiguration,\n useFactory: dbxAnalyticsServiceConfigurationFactory,\n deps: [Injector]\n },\n // service\n DbxAnalyticsService\n ];\n\n return makeEnvironmentProviders(providers);\n}\n","import { Injectable, InjectionToken, inject } from '@angular/core';\nimport { AbstractAsyncWindowLoadedService } from '@dereekb/browser';\n\n/**\n * Injection token for optionally preloading the Mixpanel SDK on the page.\n *\n * In typical setups Mixpanel is loaded by Segment device mode, so this token is rarely needed.\n */\nexport const PRELOAD_MIXPANEL_TOKEN = new InjectionToken<string>('DbxAnalyticsMixpanelApiServicePreload');\n\n/**\n * Minimal subset of the Mixpanel JS SDK surface used by the Mixpanel listener.\n *\n * Avoids taking a runtime dependency on `mixpanel-browser` since the SDK is loaded on the page\n * by Segment's Mixpanel (Actions) device-mode destination. Widen this interface if more\n * Mixpanel APIs are needed.\n */\nexport interface MixpanelLike {\n start_session_recording(): void;\n stop_session_recording(): void;\n pause_session_recording(): void;\n resume_session_recording(): void;\n}\n\n/**\n * Configuration for the Mixpanel analytics integration.\n *\n * Unlike {@link DbxAnalyticsSegmentApiServiceConfig}, this config does not take a write key —\n * Mixpanel is initialized by Segment device mode. The `active` and `logging` flags exist for\n * parity with the Segment config and to gate listener behavior.\n *\n * @example\n * ```ts\n * const config = new DbxAnalyticsMixpanelApiServiceConfig();\n * config.active = environment.production;\n * config.logging = !environment.production;\n * ```\n */\nexport class DbxAnalyticsMixpanelApiServiceConfig {\n logging = true;\n active = true;\n}\n\n/**\n * Service that manages async access to the Mixpanel JS SDK exposed on `window.mixpanel`.\n *\n * The Mixpanel SDK is typically loaded by Segment's Mixpanel (Actions) device-mode destination,\n * so this service waits for `window.mixpanel` to exist using the inherited window-loading polling.\n * The resolved SDK instance is available via the inherited `service$` observable.\n *\n * Provided via {@link provideDbxAnalyticsMixpanelApiService}.\n *\n * @example\n * ```ts\n * // In app.config.ts\n * provideDbxAnalyticsMixpanelApiService({\n * dbxAnalyticsMixpanelApiServiceConfigFactory: () => {\n * const config = new DbxAnalyticsMixpanelApiServiceConfig();\n * config.active = environment.production;\n * return config;\n * }\n * })\n * ```\n */\n@Injectable()\nexport class DbxAnalyticsMixpanelApiService extends AbstractAsyncWindowLoadedService<MixpanelLike> {\n private readonly _config = inject(DbxAnalyticsMixpanelApiServiceConfig);\n\n static readonly MIXPANEL_API_WINDOW_KEY = 'mixpanel';\n\n constructor() {\n const preload = inject(PRELOAD_MIXPANEL_TOKEN, { optional: true });\n super(DbxAnalyticsMixpanelApiService.MIXPANEL_API_WINDOW_KEY, undefined, 'Mixpanel', preload);\n }\n\n get config(): DbxAnalyticsMixpanelApiServiceConfig {\n return this._config;\n }\n}\n","import { Injectable, inject } from '@angular/core';\nimport { combineLatest } from 'rxjs';\nimport { AbstractDbxAnalyticsServiceListener, type DbxAnalyticsStreamEvent, DbxAnalyticsStreamEventType } from '../../analytics';\nimport { DbxAnalyticsMixpanelApiService, type MixpanelLike } from './mixpanel.service';\n\n/**\n * Analytics listener that forwards session-replay control events to the Mixpanel SDK.\n *\n * Handles only the four session-replay event types — track/identify/page events are intentionally\n * not forwarded here because Segment's Mixpanel (Actions) device-mode destination already routes\n * them to Mixpanel. Forwarding them again would produce duplicate events.\n *\n * - {@link DbxAnalyticsStreamEventType.StartSessionRecording} -> `mixpanel.start_session_recording()`\n * - {@link DbxAnalyticsStreamEventType.StopSessionRecording} -> `mixpanel.stop_session_recording()`\n * - {@link DbxAnalyticsStreamEventType.PauseSessionRecording} -> `mixpanel.pause_session_recording()`\n * - {@link DbxAnalyticsStreamEventType.ResumeSessionRecording} -> `mixpanel.resume_session_recording()`\n *\n * Events are only sent when the Mixpanel configuration is marked as `active`.\n * Provided at root level and registered as a listener via {@link DbxAnalyticsServiceConfiguration.listeners}.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class DbxAnalyticsMixpanelServiceListener extends AbstractDbxAnalyticsServiceListener {\n private readonly _mixpanelApi = inject(DbxAnalyticsMixpanelApiService);\n\n constructor() {\n super();\n\n if (this._mixpanelApi.config.logging) {\n console.log('MixpanelAnalyticsListenerService: Mixpanel is logging events.');\n }\n\n if (!this._mixpanelApi.config.active) {\n console.log('MixpanelAnalyticsListenerService: Mixpanel is disabled from sending events to the server.');\n }\n }\n\n protected _initializeServiceSubscription() {\n return combineLatest([this._mixpanelApi.service$, this.analyticsEvents$]).subscribe(([mixpanel, streamEvent]: [MixpanelLike, DbxAnalyticsStreamEvent]) => {\n if (this._mixpanelApi.config.logging) {\n console.log('Mixpanel Listener Logging Event: ', streamEvent);\n }\n\n if (this._mixpanelApi.config.active) {\n this.handleStreamEvent(mixpanel, streamEvent);\n }\n });\n }\n\n /**\n * Routes a session-replay control event to the corresponding Mixpanel SDK method.\n *\n * Non-session-replay events are intentionally ignored — Segment's device-mode integration\n * already forwards track/identify/page to Mixpanel.\n *\n * @param api - The loaded Mixpanel SDK instance\n * @param streamEvent - The analytics event to process\n */\n protected handleStreamEvent(api: MixpanelLike, streamEvent: DbxAnalyticsStreamEvent): void {\n switch (streamEvent.type) {\n case DbxAnalyticsStreamEventType.StartSessionRecording:\n api.start_session_recording();\n break;\n case DbxAnalyticsStreamEventType.StopSessionRecording:\n api.stop_session_recording();\n break;\n case DbxAnalyticsStreamEventType.PauseSessionRecording:\n api.pause_session_recording();\n break;\n case DbxAnalyticsStreamEventType.ResumeSessionRecording:\n api.resume_session_recording();\n break;\n default:\n // All other event types are routed to Mixpanel by Segment's device-mode destination.\n break;\n }\n }\n}\n","import { type EnvironmentProviders, Injector, makeEnvironmentProviders, type Provider } from '@angular/core';\nimport { DbxAnalyticsMixpanelApiService, DbxAnalyticsMixpanelApiServiceConfig, PRELOAD_MIXPANEL_TOKEN } from './mixpanel.service';\n\n/**\n * Factory function that creates a {@link DbxAnalyticsMixpanelApiServiceConfig} using the Angular injector.\n *\n * Used by {@link provideDbxAnalyticsMixpanelApiService} to defer Mixpanel configuration to runtime.\n */\nexport type DbxAnalyticsMixpanelApiServiceConfigFactory = (injector: Injector) => DbxAnalyticsMixpanelApiServiceConfig;\n\n/**\n * Configuration for {@link provideDbxAnalyticsMixpanelApiService}.\n */\nexport interface ProvideDbxAnalyticsMixpanelModuleConfig {\n /**\n * Whether to preload the Mixpanel script token.\n *\n * Rarely needed — Mixpanel is typically loaded by Segment's device-mode destination.\n */\n readonly preloadMixpanelToken?: boolean;\n /**\n * Factory function that produces the Mixpanel API service configuration.\n */\n readonly dbxAnalyticsMixpanelApiServiceConfigFactory: DbxAnalyticsMixpanelApiServiceConfigFactory;\n}\n\n/**\n * Creates Angular environment providers that register {@link DbxAnalyticsMixpanelApiService} for Mixpanel session-replay control.\n *\n * Use alongside {@link provideDbxAnalyticsService} to wire Mixpanel as an analytics listener that\n * handles session-replay start/stop/pause/resume events.\n *\n * @param config - Mixpanel-specific configuration\n * @returns environment providers for Mixpanel analytics\n *\n * @example\n * ```ts\n * // In app.config.ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideDbxAnalyticsMixpanelApiService({\n * dbxAnalyticsMixpanelApiServiceConfigFactory: () => {\n * const config = new DbxAnalyticsMixpanelApiServiceConfig();\n * config.active = environment.production;\n * return config;\n * }\n * }),\n * provideDbxAnalyticsService({\n * dbxAnalyticsServiceConfigurationFactory: (injector) => ({\n * isProduction: environment.production,\n * listeners: [\n * injector.get(DbxAnalyticsSegmentServiceListener),\n * injector.get(DbxAnalyticsMixpanelServiceListener)\n * ]\n * })\n * })\n * ]\n * };\n * ```\n */\nexport function provideDbxAnalyticsMixpanelApiService(config: ProvideDbxAnalyticsMixpanelModuleConfig): EnvironmentProviders {\n const { preloadMixpanelToken, dbxAnalyticsMixpanelApiServiceConfigFactory } = config;\n\n const providers: Provider[] = [\n // configuration\n {\n provide: DbxAnalyticsMixpanelApiServiceConfig,\n useFactory: dbxAnalyticsMixpanelApiServiceConfigFactory,\n deps: [Injector]\n },\n // service\n DbxAnalyticsMixpanelApiService\n ];\n\n if (preloadMixpanelToken) {\n providers.push({\n provide: PRELOAD_MIXPANEL_TOKEN,\n useValue: preloadMixpanelToken\n });\n }\n\n return makeEnvironmentProviders(providers);\n}\n","import { Injectable, InjectionToken, inject } from '@angular/core';\nimport { AbstractAsyncWindowLoadedService } from '@dereekb/browser';\nimport { poll } from '@dereekb/util';\n\n/**\n * Injection token for optionally preloading the Segment analytics script.\n */\nexport const PRELOAD_SEGMENT_TOKEN = new InjectionToken<string>('DbxAnalyticsSegmentApiServicePreload');\n\n/**\n * Configuration for the Segment analytics integration.\n *\n * @example\n * ```ts\n * const config = new DbxAnalyticsSegmentApiServiceConfig('your-segment-write-key');\n * config.active = environment.production;\n * config.logging = !environment.production;\n * ```\n */\nexport class DbxAnalyticsSegmentApiServiceConfig {\n writeKey: string;\n logging = true;\n active = true;\n constructor(writeKey: string) {\n this.writeKey = writeKey;\n }\n}\n\n/**\n * Extended Segment analytics type that includes the `invoked` flag set after the snippet initializes.\n */\ntype SegmentAnalyticsInvoked = SegmentAnalytics.AnalyticsJS & { invoked?: boolean };\n\n/**\n * Service that manages the async loading and initialization of the Segment analytics SDK from `window.analytics`.\n *\n * Polls for the Segment snippet to be invoked, then calls `analytics.load()` with the configured write key.\n * Once Segment reports ready, the resolved SDK instance is available via the inherited `service$` observable.\n *\n * Requires the Segment analytics snippet to be included in `index.html`.\n *\n * Provided via {@link provideDbxAnalyticsSegmentApiService}.\n *\n * @example\n * ```ts\n * // In app.config.ts\n * provideDbxAnalyticsSegmentApiService({\n * dbxAnalyticsSegmentApiServiceConfigFactory: (injector) => {\n * const config = new DbxAnalyticsSegmentApiServiceConfig(environment.analytics.segment);\n * config.active = environment.production;\n * return config;\n * }\n * })\n * ```\n */\n@Injectable()\nexport class DbxAnalyticsSegmentApiService extends AbstractAsyncWindowLoadedService<SegmentAnalytics.AnalyticsJS> {\n private readonly _config = inject(DbxAnalyticsSegmentApiServiceConfig);\n\n static readonly SEGMENT_API_WINDOW_KEY = 'analytics';\n static readonly SEGMENT_READY_KEY = 'SegmentReady';\n\n constructor() {\n const preload = inject(PRELOAD_SEGMENT_TOKEN, { optional: true });\n super(DbxAnalyticsSegmentApiService.SEGMENT_API_WINDOW_KEY, undefined, 'Segment', preload);\n }\n\n get config(): DbxAnalyticsSegmentApiServiceConfig {\n return this._config;\n }\n\n protected override _prepareCompleteLoadingService(): Promise<void> {\n return poll({\n // poll until analytics.invoked is true.\n check: () => Boolean((window.analytics as SegmentAnalyticsInvoked).invoked),\n timesToGiveup: 100\n });\n }\n\n protected override _initService(service: SegmentAnalytics.AnalyticsJS): Promise<SegmentAnalytics.AnalyticsJS> {\n return new Promise((resolve, reject) => {\n try {\n service.load(this._config.writeKey); // Initialize Segment\n\n // Wait for the service to ready itself.\n service.ready(() => {\n // Segment changes itself or rather the target, and the previous initial target is ignored after.\n const segment: SegmentAnalytics.AnalyticsJS = window[DbxAnalyticsSegmentApiService.SEGMENT_API_WINDOW_KEY];\n resolve(segment);\n });\n } catch (e) {\n console.log('Failed to init segment: ' + e);\n reject(e);\n }\n });\n }\n}\n","import { Injectable, inject } from '@angular/core';\nimport { type Maybe } from '@dereekb/util';\nimport { combineLatest } from 'rxjs';\nimport { AbstractDbxAnalyticsServiceListener, type DbxAnalyticsStreamEvent, DbxAnalyticsStreamEventType, type AnalyticsUser } from '../../analytics';\nimport { DbxAnalyticsSegmentApiService } from './segment.service';\n\n/**\n * Analytics listener that forwards {@link DbxAnalyticsStreamEvent} events to the Segment SDK.\n *\n * Automatically maps event types to the appropriate Segment methods:\n * - {@link DbxAnalyticsStreamEventType.Event} / {@link DbxAnalyticsStreamEventType.UserLoginEvent} -> `track()`\n * - {@link DbxAnalyticsStreamEventType.UserChange} / {@link DbxAnalyticsStreamEventType.NewUserEvent} -> `identify()`\n * - {@link DbxAnalyticsStreamEventType.UserLogoutEvent} -> `reset()`\n * - {@link DbxAnalyticsStreamEventType.PageView} -> `page()`\n *\n * Events are only sent when the Segment configuration is marked as `active`.\n * Provided at root level and registered as a listener via {@link DbxAnalyticsServiceConfiguration.listeners}.\n *\n * @example\n * ```ts\n * // Register in analytics configuration factory\n * function analyticsConfigFactory(injector: Injector): DbxAnalyticsServiceConfiguration {\n * const segmentListener = injector.get(DbxAnalyticsSegmentServiceListener);\n * return {\n * isProduction: true,\n * listeners: [segmentListener]\n * };\n * }\n * ```\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class DbxAnalyticsSegmentServiceListener extends AbstractDbxAnalyticsServiceListener {\n private readonly _segmentApi = inject(DbxAnalyticsSegmentApiService);\n\n constructor() {\n super();\n\n if (this._segmentApi.config.logging) {\n console.log('SegmentAnalyticsListenerService: Segment is logging events.');\n }\n\n if (!this._segmentApi.config.active) {\n console.log('SegmentAnalyticsListenerService: Segment is disabled from sending events to the server.');\n }\n }\n\n /**\n * Subscribes to the Segment API service and analytics event stream, forwarding events to the Segment SDK.\n *\n * Events are only sent when the Segment configuration is marked as active.\n *\n * @returns subscription to the combined Segment API and analytics event stream\n */\n protected _initializeServiceSubscription() {\n return combineLatest([this._segmentApi.service$, this.analyticsEvents$]).subscribe(([segment, streamEvent]: [SegmentAnalytics.AnalyticsJS, DbxAnalyticsStreamEvent]) => {\n if (this._segmentApi.config.logging) {\n console.log('Segment Listener Logging Event: ', streamEvent);\n }\n\n if (this._segmentApi.config.active) {\n this.handleStreamEvent(segment, streamEvent);\n }\n });\n }\n\n /**\n * Routes an analytics stream event to the appropriate Segment API method based on event type.\n *\n * @param api - The Segment analytics SDK instance\n * @param streamEvent - The analytics event to process\n */\n protected handleStreamEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent): void {\n switch (streamEvent.type) {\n case DbxAnalyticsStreamEventType.NewUserEvent:\n this.updateWithNewUserEvent(api, streamEvent);\n break;\n case DbxAnalyticsStreamEventType.UserLoginEvent:\n this.changeUser(api, streamEvent.user);\n this.updateWithEvent(api, streamEvent);\n break;\n case DbxAnalyticsStreamEventType.Event:\n this.updateWithEvent(api, streamEvent);\n break;\n case DbxAnalyticsStreamEventType.UserLogoutEvent:\n this.changeUser(api, undefined);\n break;\n case DbxAnalyticsStreamEventType.PageView:\n api.page();\n break;\n case DbxAnalyticsStreamEventType.UserChange:\n this.changeUser(api, streamEvent.user);\n break;\n case DbxAnalyticsStreamEventType.UserIdChange:\n case DbxAnalyticsStreamEventType.UserPropertiesEvent:\n case DbxAnalyticsStreamEventType.StartSessionRecording:\n case DbxAnalyticsStreamEventType.StopSessionRecording:\n case DbxAnalyticsStreamEventType.PauseSessionRecording:\n case DbxAnalyticsStreamEventType.ResumeSessionRecording:\n // These event types are not forwarded to Segment.\n break;\n }\n }\n\n /**\n * Handles a new user registration event by identifying the user in Segment.\n *\n * @param api - The Segment analytics SDK instance\n * @param streamEvent - The event containing the new user data\n */\n protected updateWithNewUserEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent): void {\n this.changeUser(api, streamEvent.user);\n }\n\n /**\n * Sends a track event to Segment with the event name, value, and additional data properties.\n *\n * @param api - The Segment analytics SDK instance\n * @param streamEvent - The analytics event containing name, value, and data\n * @param name - Optional override for the event name\n */\n protected updateWithEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent, name?: string): void {\n const event = streamEvent.event;\n const eventName = name || event?.name;\n\n if (eventName) {\n const value = event?.value;\n const data = event?.data;\n\n api.track(\n eventName,\n {\n ...(value != null\n ? {\n value\n }\n : undefined),\n ...data\n },\n {},\n () => {\n if (this._segmentApi.config.logging) {\n console.log('Segment track success.');\n }\n }\n );\n }\n }\n\n private changeUser(api: SegmentAnalytics.AnalyticsJS, user: Maybe<AnalyticsUser>): void {\n if (user?.user) {\n api.identify(\n user.user,\n {\n ...user.properties\n },\n {},\n () => {\n if (this._segmentApi.config.logging) {\n console.log('Segment identify success.');\n }\n }\n );\n } else {\n api.reset();\n }\n }\n}\n","import { type EnvironmentProviders, Injector, makeEnvironmentProviders, type Provider } from '@angular/core';\nimport { DbxAnalyticsSegmentApiService, DbxAnalyticsSegmentApiServiceConfig, PRELOAD_SEGMENT_TOKEN } from './segment.service';\n\n/**\n * Factory function that creates a {@link DbxAnalyticsSegmentApiServiceConfig} using the Angular injector.\n *\n * Used by {@link provideDbxAnalyticsSegmentApiService} to defer Segment configuration to runtime.\n */\nexport type DbxAnalyticsSegmentApiServiceConfigFactory = (injector: Injector) => DbxAnalyticsSegmentApiServiceConfig;\n\n/**\n * Configuration for {@link provideDbxAnalyticsSegmentApiService}.\n */\nexport interface ProvideDbxAnalyticsSegmentModuleConfig {\n /**\n * Whether to preload the Segment script token.\n */\n readonly preloadSegmentToken?: boolean;\n /**\n * Factory function that produces the Segment API service configuration.\n */\n readonly dbxAnalyticsSegmentApiServiceConfigFactory: DbxAnalyticsSegmentApiServiceConfigFactory;\n}\n\n/**\n * Creates Angular environment providers that register {@link DbxAnalyticsSegmentApiService} for Segment analytics integration.\n *\n * Use alongside {@link provideDbxAnalyticsService} to wire Segment as an analytics listener.\n *\n * @param config - Segment-specific configuration including the write key factory\n * @returns environment providers for Segment analytics\n *\n * @example\n * ```ts\n * // In app.config.ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideDbxAnalyticsSegmentApiService({\n * dbxAnalyticsSegmentApiServiceConfigFactory: (injector) => {\n * const config = new DbxAnalyticsSegmentApiServiceConfig(environment.analytics.segment);\n * config.active = environment.production;\n * config.logging = !environment.production;\n * return config;\n * }\n * }),\n * provideDbxAnalyticsService({\n * dbxAnalyticsServiceConfigurationFactory: (injector) => ({\n * isProduction: environment.production,\n * listeners: [injector.get(DbxAnalyticsSegmentServiceListener)]\n * })\n * })\n * ]\n * };\n * ```\n */\nexport function provideDbxAnalyticsSegmentApiService(config: ProvideDbxAnalyticsSegmentModuleConfig): EnvironmentProviders {\n const { preloadSegmentToken, dbxAnalyticsSegmentApiServiceConfigFactory } = config;\n\n const providers: Provider[] = [\n // configuration\n {\n provide: DbxAnalyticsSegmentApiServiceConfig,\n useFactory: dbxAnalyticsSegmentApiServiceConfigFactory,\n deps: [Injector]\n },\n // service\n DbxAnalyticsSegmentApiService\n ];\n\n if (preloadSegmentToken) {\n providers.push({\n provide: PRELOAD_SEGMENT_TOKEN,\n useValue: preloadSegmentToken\n });\n }\n\n return makeEnvironmentProviders(providers);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAGA;;;;;AAKG;IACS;AAAZ,CAAA,UAAY,2BAA2B,EAAA;AACrC;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,UAAA,CAAA,GAAA,CAAA,CAAA,GAAA,UAAQ;AACR;;;;AAIG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU;AACV;;;;AAIG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,cAAA,CAAA,GAAA,CAAA,CAAA,GAAA,cAAY;;AAGZ;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,cAAA,CAAA,GAAA,CAAA,CAAA,GAAA,cAAY;AACZ;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,gBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,gBAAc;AACd;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,iBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,iBAAe;AACf;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,qBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,qBAAmB;;AAGnB;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK;;AAGL;;AAEG;AACH,IAAA,2BAAA,CAAA,2BAAA,CAAA,uBAAA,CAAA,GAAA,CAAA,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,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAlC,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,kCAAkC,cAFjC,MAAM,EAAA,CAAA;;4FAEP,kCAAkC,EAAA,UAAA,EAAA,CAAA;kBAH9C,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACRD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACG,SAAU,oCAAoC,CAAC,MAA8C,EAAA;AACjG,IAAA,MAAM,EAAE,mBAAmB,EAAE,0CAA0C,EAAE,GAAG,MAAM;AAElF,IAAA,MAAM,SAAS,GAAe;;AAE5B,QAAA;AACE,YAAA,OAAO,EAAE,mCAAmC;AAC5C,YAAA,UAAU,EAAE,0CAA0C;YACtD,IAAI,EAAE,CAAC,QAAQ;AAChB,SAAA;;QAED;KACD;IAED,IAAI,mBAAmB,EAAE;QACvB,SAAS,CAAC,IAAI,CAAC;AACb,YAAA,OAAO,EAAE,qBAAqB;AAC9B,YAAA,QAAQ,EAAE;AACX,SAAA,CAAC;IACJ;AAEA,IAAA,OAAO,wBAAwB,CAAC,SAAS,CAAC;AAC5C;;AC7EA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@dereekb/dbx-analytics",
3
- "version": "13.10.2",
3
+ "version": "13.10.3",
4
4
  "peerDependencies": {
5
5
  "@angular/core": "21.2.10",
6
- "@dereekb/analytics": "13.10.2",
7
- "@dereekb/browser": "13.10.2",
8
- "@dereekb/dbx-core": "13.10.2",
9
- "@dereekb/rxjs": "13.10.2",
10
- "@dereekb/util": "13.10.2",
11
- "@dereekb/vitest": "13.10.2",
6
+ "@dereekb/analytics": "13.10.3",
7
+ "@dereekb/browser": "13.10.3",
8
+ "@dereekb/dbx-core": "13.10.3",
9
+ "@dereekb/rxjs": "13.10.3",
10
+ "@dereekb/util": "13.10.3",
11
+ "@dereekb/vitest": "13.10.3",
12
12
  "rxjs": "^7.8.2"
13
13
  },
14
14
  "dependencies": {
@@ -79,7 +79,23 @@ declare enum DbxAnalyticsStreamEventType {
79
79
  /**
80
80
  * A generic custom analytics event.
81
81
  */
82
- Event = 7
82
+ Event = 7,
83
+ /**
84
+ * Request to start session replay recording.
85
+ */
86
+ StartSessionRecording = 8,
87
+ /**
88
+ * Request to stop session replay recording.
89
+ */
90
+ StopSessionRecording = 9,
91
+ /**
92
+ * Request to pause an active session replay recording without clearing it.
93
+ */
94
+ PauseSessionRecording = 10,
95
+ /**
96
+ * Request to resume a previously paused session replay recording.
97
+ */
98
+ ResumeSessionRecording = 11
83
99
  }
84
100
  /**
85
101
  * Represents a single event in the analytics stream, combining the event type, payload, and user context.
@@ -127,6 +143,10 @@ declare abstract class DbxAnalyticsEventEmitterService {
127
143
  abstract sendEventData(name: AnalyticsEventName, data: AnalyticsEventData): void;
128
144
  abstract sendEvent(event: AnalyticsEvent): void;
129
145
  abstract sendPageView(page?: string): void;
146
+ abstract startSessionRecording(): void;
147
+ abstract stopSessionRecording(): void;
148
+ abstract pauseSessionRecording(): void;
149
+ abstract resumeSessionRecording(): void;
130
150
  }
131
151
  /**
132
152
  * Abstract interface exposing the analytics event stream as an observable.
@@ -377,6 +397,31 @@ declare class DbxAnalyticsService implements DbxAnalyticsEventStreamService, Dbx
377
397
  * ```
378
398
  */
379
399
  sendPageView(page?: string): void;
400
+ /**
401
+ * Requests that opt-in listeners (e.g. Mixpanel) start session replay recording.
402
+ *
403
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.StartSessionRecording} event. Listeners
404
+ * that don't handle session replay (e.g. Segment) ignore it.
405
+ */
406
+ startSessionRecording(): void;
407
+ /**
408
+ * Requests that opt-in listeners stop session replay recording.
409
+ *
410
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.StopSessionRecording} event.
411
+ */
412
+ stopSessionRecording(): void;
413
+ /**
414
+ * Requests that opt-in listeners pause active session replay recording without clearing it.
415
+ *
416
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.PauseSessionRecording} event.
417
+ */
418
+ pauseSessionRecording(): void;
419
+ /**
420
+ * Requests that opt-in listeners resume previously paused session replay recording.
421
+ *
422
+ * Forwarded as a {@link DbxAnalyticsStreamEventType.ResumeSessionRecording} event.
423
+ */
424
+ resumeSessionRecording(): void;
380
425
  /**
381
426
  * Sends the next event.
382
427
  *
@@ -510,6 +555,163 @@ interface ProvideDbxAnalyticsConfig {
510
555
  */
511
556
  declare function provideDbxAnalyticsService(config: ProvideDbxAnalyticsConfig): EnvironmentProviders;
512
557
 
558
+ /**
559
+ * Injection token for optionally preloading the Mixpanel SDK on the page.
560
+ *
561
+ * In typical setups Mixpanel is loaded by Segment device mode, so this token is rarely needed.
562
+ */
563
+ declare const PRELOAD_MIXPANEL_TOKEN: InjectionToken<string>;
564
+ /**
565
+ * Minimal subset of the Mixpanel JS SDK surface used by the Mixpanel listener.
566
+ *
567
+ * Avoids taking a runtime dependency on `mixpanel-browser` since the SDK is loaded on the page
568
+ * by Segment's Mixpanel (Actions) device-mode destination. Widen this interface if more
569
+ * Mixpanel APIs are needed.
570
+ */
571
+ interface MixpanelLike {
572
+ start_session_recording(): void;
573
+ stop_session_recording(): void;
574
+ pause_session_recording(): void;
575
+ resume_session_recording(): void;
576
+ }
577
+ /**
578
+ * Configuration for the Mixpanel analytics integration.
579
+ *
580
+ * Unlike {@link DbxAnalyticsSegmentApiServiceConfig}, this config does not take a write key —
581
+ * Mixpanel is initialized by Segment device mode. The `active` and `logging` flags exist for
582
+ * parity with the Segment config and to gate listener behavior.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * const config = new DbxAnalyticsMixpanelApiServiceConfig();
587
+ * config.active = environment.production;
588
+ * config.logging = !environment.production;
589
+ * ```
590
+ */
591
+ declare class DbxAnalyticsMixpanelApiServiceConfig {
592
+ logging: boolean;
593
+ active: boolean;
594
+ }
595
+ /**
596
+ * Service that manages async access to the Mixpanel JS SDK exposed on `window.mixpanel`.
597
+ *
598
+ * The Mixpanel SDK is typically loaded by Segment's Mixpanel (Actions) device-mode destination,
599
+ * so this service waits for `window.mixpanel` to exist using the inherited window-loading polling.
600
+ * The resolved SDK instance is available via the inherited `service$` observable.
601
+ *
602
+ * Provided via {@link provideDbxAnalyticsMixpanelApiService}.
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * // In app.config.ts
607
+ * provideDbxAnalyticsMixpanelApiService({
608
+ * dbxAnalyticsMixpanelApiServiceConfigFactory: () => {
609
+ * const config = new DbxAnalyticsMixpanelApiServiceConfig();
610
+ * config.active = environment.production;
611
+ * return config;
612
+ * }
613
+ * })
614
+ * ```
615
+ */
616
+ declare class DbxAnalyticsMixpanelApiService extends AbstractAsyncWindowLoadedService<MixpanelLike> {
617
+ private readonly _config;
618
+ static readonly MIXPANEL_API_WINDOW_KEY = "mixpanel";
619
+ constructor();
620
+ get config(): DbxAnalyticsMixpanelApiServiceConfig;
621
+ static ɵfac: i0.ɵɵFactoryDeclaration<DbxAnalyticsMixpanelApiService, never>;
622
+ static ɵprov: i0.ɵɵInjectableDeclaration<DbxAnalyticsMixpanelApiService>;
623
+ }
624
+
625
+ /**
626
+ * Analytics listener that forwards session-replay control events to the Mixpanel SDK.
627
+ *
628
+ * Handles only the four session-replay event types — track/identify/page events are intentionally
629
+ * not forwarded here because Segment's Mixpanel (Actions) device-mode destination already routes
630
+ * them to Mixpanel. Forwarding them again would produce duplicate events.
631
+ *
632
+ * - {@link DbxAnalyticsStreamEventType.StartSessionRecording} -> `mixpanel.start_session_recording()`
633
+ * - {@link DbxAnalyticsStreamEventType.StopSessionRecording} -> `mixpanel.stop_session_recording()`
634
+ * - {@link DbxAnalyticsStreamEventType.PauseSessionRecording} -> `mixpanel.pause_session_recording()`
635
+ * - {@link DbxAnalyticsStreamEventType.ResumeSessionRecording} -> `mixpanel.resume_session_recording()`
636
+ *
637
+ * Events are only sent when the Mixpanel configuration is marked as `active`.
638
+ * Provided at root level and registered as a listener via {@link DbxAnalyticsServiceConfiguration.listeners}.
639
+ */
640
+ declare class DbxAnalyticsMixpanelServiceListener extends AbstractDbxAnalyticsServiceListener {
641
+ private readonly _mixpanelApi;
642
+ constructor();
643
+ protected _initializeServiceSubscription(): rxjs.Subscription;
644
+ /**
645
+ * Routes a session-replay control event to the corresponding Mixpanel SDK method.
646
+ *
647
+ * Non-session-replay events are intentionally ignored — Segment's device-mode integration
648
+ * already forwards track/identify/page to Mixpanel.
649
+ *
650
+ * @param api - The loaded Mixpanel SDK instance
651
+ * @param streamEvent - The analytics event to process
652
+ */
653
+ protected handleStreamEvent(api: MixpanelLike, streamEvent: DbxAnalyticsStreamEvent): void;
654
+ static ɵfac: i0.ɵɵFactoryDeclaration<DbxAnalyticsMixpanelServiceListener, never>;
655
+ static ɵprov: i0.ɵɵInjectableDeclaration<DbxAnalyticsMixpanelServiceListener>;
656
+ }
657
+
658
+ /**
659
+ * Factory function that creates a {@link DbxAnalyticsMixpanelApiServiceConfig} using the Angular injector.
660
+ *
661
+ * Used by {@link provideDbxAnalyticsMixpanelApiService} to defer Mixpanel configuration to runtime.
662
+ */
663
+ type DbxAnalyticsMixpanelApiServiceConfigFactory = (injector: Injector) => DbxAnalyticsMixpanelApiServiceConfig;
664
+ /**
665
+ * Configuration for {@link provideDbxAnalyticsMixpanelApiService}.
666
+ */
667
+ interface ProvideDbxAnalyticsMixpanelModuleConfig {
668
+ /**
669
+ * Whether to preload the Mixpanel script token.
670
+ *
671
+ * Rarely needed — Mixpanel is typically loaded by Segment's device-mode destination.
672
+ */
673
+ readonly preloadMixpanelToken?: boolean;
674
+ /**
675
+ * Factory function that produces the Mixpanel API service configuration.
676
+ */
677
+ readonly dbxAnalyticsMixpanelApiServiceConfigFactory: DbxAnalyticsMixpanelApiServiceConfigFactory;
678
+ }
679
+ /**
680
+ * Creates Angular environment providers that register {@link DbxAnalyticsMixpanelApiService} for Mixpanel session-replay control.
681
+ *
682
+ * Use alongside {@link provideDbxAnalyticsService} to wire Mixpanel as an analytics listener that
683
+ * handles session-replay start/stop/pause/resume events.
684
+ *
685
+ * @param config - Mixpanel-specific configuration
686
+ * @returns environment providers for Mixpanel analytics
687
+ *
688
+ * @example
689
+ * ```ts
690
+ * // In app.config.ts
691
+ * export const appConfig: ApplicationConfig = {
692
+ * providers: [
693
+ * provideDbxAnalyticsMixpanelApiService({
694
+ * dbxAnalyticsMixpanelApiServiceConfigFactory: () => {
695
+ * const config = new DbxAnalyticsMixpanelApiServiceConfig();
696
+ * config.active = environment.production;
697
+ * return config;
698
+ * }
699
+ * }),
700
+ * provideDbxAnalyticsService({
701
+ * dbxAnalyticsServiceConfigurationFactory: (injector) => ({
702
+ * isProduction: environment.production,
703
+ * listeners: [
704
+ * injector.get(DbxAnalyticsSegmentServiceListener),
705
+ * injector.get(DbxAnalyticsMixpanelServiceListener)
706
+ * ]
707
+ * })
708
+ * })
709
+ * ]
710
+ * };
711
+ * ```
712
+ */
713
+ declare function provideDbxAnalyticsMixpanelApiService(config: ProvideDbxAnalyticsMixpanelModuleConfig): EnvironmentProviders;
714
+
513
715
  /**
514
716
  * Analytics listener that forwards {@link DbxAnalyticsStreamEvent} events to the Segment SDK.
515
717
  *
@@ -678,5 +880,5 @@ interface ProvideDbxAnalyticsSegmentModuleConfig {
678
880
  */
679
881
  declare function provideDbxAnalyticsSegmentApiService(config: ProvideDbxAnalyticsSegmentModuleConfig): EnvironmentProviders;
680
882
 
681
- export { AbstractDbxAnalyticsServiceListener, DbxActionAnalyticsDirective, DbxAnalyticsActionModule, DbxAnalyticsEventEmitterService, DbxAnalyticsEventStreamService, DbxAnalyticsSegmentApiService, DbxAnalyticsSegmentApiServiceConfig, DbxAnalyticsSegmentServiceListener, DbxAnalyticsService, DbxAnalyticsServiceConfiguration, DbxAnalyticsServiceListener, DbxAnalyticsStreamEventType, DbxAnalyticsUserSource, PRELOAD_SEGMENT_TOKEN, dbxAnalyticsStreamEventAnalyticsEventWrapper, provideDbxAnalyticsSegmentApiService, provideDbxAnalyticsService };
682
- export type { DbxActionAnalyticsConfig, DbxAnalyticsEvent, DbxAnalyticsEventData, DbxAnalyticsEventName, DbxAnalyticsSegmentApiServiceConfigFactory, DbxAnalyticsServiceConfigurationFactory, DbxAnalyticsStreamEvent, DbxAnalyticsStreamEventAnalyticsEventWrapper, DbxAnalyticsUser, DbxAnalyticsUserId, DbxAnalyticsUserProperties, DbxUserAnalyticsEvent, ProvideDbxAnalyticsConfig, ProvideDbxAnalyticsSegmentModuleConfig };
883
+ export { AbstractDbxAnalyticsServiceListener, DbxActionAnalyticsDirective, DbxAnalyticsActionModule, DbxAnalyticsEventEmitterService, DbxAnalyticsEventStreamService, DbxAnalyticsMixpanelApiService, DbxAnalyticsMixpanelApiServiceConfig, DbxAnalyticsMixpanelServiceListener, DbxAnalyticsSegmentApiService, DbxAnalyticsSegmentApiServiceConfig, DbxAnalyticsSegmentServiceListener, DbxAnalyticsService, DbxAnalyticsServiceConfiguration, DbxAnalyticsServiceListener, DbxAnalyticsStreamEventType, DbxAnalyticsUserSource, PRELOAD_MIXPANEL_TOKEN, PRELOAD_SEGMENT_TOKEN, dbxAnalyticsStreamEventAnalyticsEventWrapper, provideDbxAnalyticsMixpanelApiService, provideDbxAnalyticsSegmentApiService, provideDbxAnalyticsService };
884
+ export type { DbxActionAnalyticsConfig, DbxAnalyticsEvent, DbxAnalyticsEventData, DbxAnalyticsEventName, DbxAnalyticsMixpanelApiServiceConfigFactory, DbxAnalyticsSegmentApiServiceConfigFactory, DbxAnalyticsServiceConfigurationFactory, DbxAnalyticsStreamEvent, DbxAnalyticsStreamEventAnalyticsEventWrapper, DbxAnalyticsUser, DbxAnalyticsUserId, DbxAnalyticsUserProperties, DbxUserAnalyticsEvent, MixpanelLike, ProvideDbxAnalyticsConfig, ProvideDbxAnalyticsMixpanelModuleConfig, ProvideDbxAnalyticsSegmentModuleConfig };