@dereekb/dbx-analytics 13.2.2 → 13.3.1
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.
|
@@ -6,49 +6,155 @@ import { DbxActionContextStoreSourceInstance } from '@dereekb/dbx-core';
|
|
|
6
6
|
import { PrimativeKey, Maybe, Destroyable, ReadableError } from '@dereekb/util';
|
|
7
7
|
import { AbstractAsyncWindowLoadedService } from '@dereekb/browser';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Name identifier for an analytics event (e.g., `'User Registered'`, `'Page Viewed'`).
|
|
11
|
+
*/
|
|
9
12
|
type DbxAnalyticsEventName = string;
|
|
13
|
+
/**
|
|
14
|
+
* Unique identifier for an analytics user, typically a UID from the auth system.
|
|
15
|
+
*/
|
|
10
16
|
type DbxAnalyticsUserId = string;
|
|
17
|
+
/**
|
|
18
|
+
* Key-value map of user properties sent alongside identify calls to analytics providers.
|
|
19
|
+
*
|
|
20
|
+
* Used to enrich user profiles in tools like Segment with traits such as roles, plan type, or onboarding status.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const properties: DbxAnalyticsUserProperties = {
|
|
25
|
+
* isOnboarded: true,
|
|
26
|
+
* role: 'admin',
|
|
27
|
+
* plan: 'pro'
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
11
31
|
interface DbxAnalyticsUserProperties {
|
|
12
32
|
readonly [key: string]: PrimativeKey | boolean;
|
|
13
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents a user for analytics identification, pairing a unique user ID with optional trait properties.
|
|
36
|
+
*
|
|
37
|
+
* Passed to analytics providers (e.g., Segment `identify()`) to associate events with a specific user.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const user: DbxAnalyticsUser = {
|
|
42
|
+
* user: 'uid_abc123',
|
|
43
|
+
* properties: { isOnboarded: true, role: 'worker' }
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
14
47
|
interface DbxAnalyticsUser {
|
|
15
48
|
readonly user: DbxAnalyticsUserId;
|
|
16
49
|
readonly properties?: DbxAnalyticsUserProperties;
|
|
17
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Key-value map of event-specific data attached to an analytics event.
|
|
53
|
+
*
|
|
54
|
+
* Sent as properties in `track()` calls to analytics providers.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const data: DbxAnalyticsEventData = {
|
|
59
|
+
* code: 'PERMISSION_DENIED',
|
|
60
|
+
* seconds: 120
|
|
61
|
+
* };
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
18
64
|
interface DbxAnalyticsEventData {
|
|
19
65
|
readonly [key: string]: PrimativeKey | boolean;
|
|
20
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Describes an analytics event with an optional name, numeric value, and arbitrary data payload.
|
|
69
|
+
*
|
|
70
|
+
* This is the core event shape emitted through {@link DbxAnalyticsService} and consumed by listeners like Segment.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const event: DbxAnalyticsEvent = {
|
|
75
|
+
* name: 'Button Clicked',
|
|
76
|
+
* value: 1,
|
|
77
|
+
* data: { buttonId: 'submit-form' }
|
|
78
|
+
* };
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
21
81
|
interface DbxAnalyticsEvent {
|
|
22
82
|
readonly name?: DbxAnalyticsEventName;
|
|
23
83
|
readonly value?: number;
|
|
24
84
|
readonly data?: DbxAnalyticsEventData;
|
|
25
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Extends {@link DbxAnalyticsEvent} with an optional user association.
|
|
88
|
+
*
|
|
89
|
+
* Used internally by {@link DbxAnalyticsService} to attach the current user context to each emitted event.
|
|
90
|
+
*/
|
|
26
91
|
interface DbxUserAnalyticsEvent extends DbxAnalyticsEvent {
|
|
27
92
|
readonly user?: Maybe<DbxAnalyticsUser>;
|
|
28
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Registration method used to create a new user account (e.g., `'facebook'`, `'google'`, `'email'`).
|
|
96
|
+
*/
|
|
29
97
|
type NewUserRegistrationMethod = 'facebook' | 'google' | 'email' | string;
|
|
98
|
+
/**
|
|
99
|
+
* Event data for new user registration events, requiring the registration method.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const data: NewUserAnalyticsEventData = {
|
|
104
|
+
* method: 'google'
|
|
105
|
+
* };
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
30
108
|
interface NewUserAnalyticsEventData extends DbxAnalyticsEventData {
|
|
31
109
|
method: NewUserRegistrationMethod;
|
|
32
110
|
}
|
|
33
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Categorizes the kind of analytics stream event emitted by {@link DbxAnalyticsService}.
|
|
114
|
+
*
|
|
115
|
+
* Listeners use this type to route events to the appropriate analytics provider method
|
|
116
|
+
* (e.g., Segment `track()`, `identify()`, `page()`).
|
|
117
|
+
*/
|
|
34
118
|
declare enum DbxAnalyticsStreamEventType {
|
|
119
|
+
/** A page/screen view event, typically sent on route transitions. */
|
|
35
120
|
PageView = 0,
|
|
36
121
|
/**
|
|
37
|
-
* Emitted any time the user value changes.
|
|
122
|
+
* Emitted any time the user value changes, including when transitioning from defined to undefined.
|
|
38
123
|
*
|
|
39
|
-
*
|
|
124
|
+
* Used by listeners to update the identified user in analytics providers.
|
|
40
125
|
*/
|
|
41
126
|
UserChange = 1,
|
|
42
127
|
/**
|
|
43
|
-
* Emitted
|
|
128
|
+
* Emitted only when the user's unique ID changes, filtering out property-only updates.
|
|
129
|
+
*
|
|
130
|
+
* Useful for triggering identity calls without redundant updates when only traits change.
|
|
44
131
|
*/
|
|
45
132
|
UserIdChange = 2,
|
|
133
|
+
/** A new user registration event. */
|
|
46
134
|
NewUserEvent = 3,
|
|
135
|
+
/** A returning user login event. */
|
|
47
136
|
UserLoginEvent = 4,
|
|
137
|
+
/** A user logout event. */
|
|
48
138
|
UserLogoutEvent = 5,
|
|
139
|
+
/** An update to user profile properties/traits. */
|
|
49
140
|
UserPropertiesEvent = 6,
|
|
141
|
+
/** A generic custom analytics event. */
|
|
50
142
|
Event = 7
|
|
51
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Represents a single event in the analytics stream, combining the event type, payload, and user context.
|
|
146
|
+
*
|
|
147
|
+
* Emitted by {@link DbxAnalyticsService} and consumed by {@link DbxAnalyticsServiceListener} implementations
|
|
148
|
+
* (e.g., {@link DbxAnalyticsSegmentServiceListener}) to forward events to external analytics providers.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* // Subscribe to the analytics event stream
|
|
153
|
+
* analyticsService.events$.subscribe((streamEvent: DbxAnalyticsStreamEvent) => {
|
|
154
|
+
* console.log(streamEvent.type, streamEvent.event?.name, streamEvent.userId);
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
52
158
|
interface DbxAnalyticsStreamEvent {
|
|
53
159
|
readonly type: DbxAnalyticsStreamEventType;
|
|
54
160
|
readonly user?: Maybe<DbxAnalyticsUser>;
|
|
@@ -56,26 +162,83 @@ interface DbxAnalyticsStreamEvent {
|
|
|
56
162
|
readonly userId?: DbxAnalyticsUserId;
|
|
57
163
|
}
|
|
58
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Abstract emitter interface for sending analytics events.
|
|
167
|
+
*
|
|
168
|
+
* Implemented by {@link DbxAnalyticsService} as the primary concrete implementation.
|
|
169
|
+
* Components and services use this to fire analytics events without coupling to a specific provider.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* // Inject and send a custom event
|
|
174
|
+
* const emitter = inject(DbxAnalyticsEventEmitterService);
|
|
175
|
+
* emitter.sendEventData('Button Clicked', { buttonId: 'save' });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
59
178
|
declare abstract class DbxAnalyticsEventEmitterService {
|
|
60
179
|
abstract sendNewUserEvent(user: DbxAnalyticsUser, data: NewUserAnalyticsEventData): void;
|
|
61
180
|
abstract sendUserLoginEvent(user: DbxAnalyticsUser, data?: DbxAnalyticsEventData): void;
|
|
62
181
|
abstract sendUserLogoutEvent(data?: DbxAnalyticsEventData): void;
|
|
63
182
|
abstract sendUserPropertiesEvent(user: DbxAnalyticsUser, data?: DbxAnalyticsEventData): void;
|
|
64
|
-
|
|
183
|
+
/**
|
|
184
|
+
* @deprecated When sending an event with no data, use {@link sendEventType} instead.
|
|
185
|
+
*/
|
|
186
|
+
abstract sendEventData(name: DbxAnalyticsEventName): void;
|
|
187
|
+
abstract sendEventData(name: DbxAnalyticsEventName, data: DbxAnalyticsEventData): void;
|
|
65
188
|
abstract sendEvent(event: DbxAnalyticsEvent): void;
|
|
66
189
|
abstract sendPageView(page?: string): void;
|
|
67
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Abstract interface exposing the analytics event stream as an observable.
|
|
193
|
+
*
|
|
194
|
+
* Implemented by {@link DbxAnalyticsService}. Listeners subscribe to `events$` to forward events to external providers.
|
|
195
|
+
*/
|
|
68
196
|
declare abstract class DbxAnalyticsEventStreamService {
|
|
69
197
|
abstract readonly events$: Observable<DbxAnalyticsStreamEvent>;
|
|
70
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Abstract source for the current analytics user identity.
|
|
201
|
+
*
|
|
202
|
+
* Provide an implementation to automatically associate a user with all emitted analytics events.
|
|
203
|
+
* Typically backed by the auth system (e.g., {@link DbxFirebaseAnalyticsUserSource}).
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* // Provide a static user source
|
|
208
|
+
* const userSource: DbxAnalyticsUserSource = {
|
|
209
|
+
* analyticsUser$: of({ user: 'uid_abc123', properties: { role: 'admin' } })
|
|
210
|
+
* };
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
71
213
|
declare abstract class DbxAnalyticsUserSource {
|
|
72
214
|
abstract readonly analyticsUser$: Observable<Maybe<DbxAnalyticsUser>>;
|
|
73
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Abstract listener that receives analytics events from {@link DbxAnalyticsService}.
|
|
218
|
+
*
|
|
219
|
+
* Implement this to forward events to an external analytics provider (e.g., Segment, Mixpanel).
|
|
220
|
+
* Register listeners via {@link DbxAnalyticsServiceConfiguration.listeners}.
|
|
221
|
+
*/
|
|
74
222
|
declare abstract class DbxAnalyticsServiceListener {
|
|
75
223
|
abstract listenToService(service: DbxAnalyticsService): void;
|
|
76
224
|
}
|
|
77
225
|
/**
|
|
78
|
-
*
|
|
226
|
+
* Base class for analytics service listeners that manages subscription lifecycle and provides
|
|
227
|
+
* reactive access to the analytics service and its event stream.
|
|
228
|
+
*
|
|
229
|
+
* Subclasses implement {@link _initializeServiceSubscription} to subscribe to events and forward them
|
|
230
|
+
* to an external analytics provider.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* class MyAnalyticsListener extends AbstractDbxAnalyticsServiceListener {
|
|
235
|
+
* protected _initializeServiceSubscription(): Subscription | false {
|
|
236
|
+
* return this.analyticsEvents$.subscribe((event) => {
|
|
237
|
+
* console.log('Event:', event.type, event.event?.name);
|
|
238
|
+
* });
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
79
242
|
*/
|
|
80
243
|
declare abstract class AbstractDbxAnalyticsServiceListener implements DbxAnalyticsServiceListener, Destroyable {
|
|
81
244
|
private _sub;
|
|
@@ -86,18 +249,57 @@ declare abstract class AbstractDbxAnalyticsServiceListener implements DbxAnalyti
|
|
|
86
249
|
protected abstract _initializeServiceSubscription(): Subscription | false;
|
|
87
250
|
destroy(): void;
|
|
88
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Configuration for {@link DbxAnalyticsService}, controlling which listeners receive events,
|
|
254
|
+
* whether analytics runs in production mode, and optionally providing a user source.
|
|
255
|
+
*
|
|
256
|
+
* In non-production mode, listeners are not initialized and all events are logged to the console instead.
|
|
257
|
+
* Provide via {@link provideDbxAnalyticsService} using a factory function.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```ts
|
|
261
|
+
* const config: DbxAnalyticsServiceConfiguration = {
|
|
262
|
+
* isProduction: environment.production,
|
|
263
|
+
* logEvents: !environment.production,
|
|
264
|
+
* listeners: [segmentListener],
|
|
265
|
+
* userSource: firebaseAnalyticsUserSource
|
|
266
|
+
* };
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
89
269
|
declare abstract class DbxAnalyticsServiceConfiguration {
|
|
90
270
|
readonly listeners: DbxAnalyticsServiceListener[];
|
|
91
271
|
readonly isProduction?: boolean;
|
|
92
272
|
readonly logEvents?: boolean;
|
|
93
273
|
readonly userSource?: DbxAnalyticsUserSource;
|
|
94
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* A fully resolved analytics stream event that includes the event payload, type, user context, and extracted user ID.
|
|
277
|
+
*
|
|
278
|
+
* Created by {@link dbxAnalyticsStreamEventAnalyticsEventWrapper} and emitted through the analytics event stream.
|
|
279
|
+
*/
|
|
95
280
|
interface DbxAnalyticsStreamEventAnalyticsEventWrapper extends DbxAnalyticsStreamEvent {
|
|
96
281
|
readonly event: DbxUserAnalyticsEvent;
|
|
97
282
|
readonly type: DbxAnalyticsStreamEventType;
|
|
98
283
|
readonly user: Maybe<DbxAnalyticsUser>;
|
|
99
284
|
readonly userId: string | undefined;
|
|
100
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Wraps a {@link DbxUserAnalyticsEvent} into a {@link DbxAnalyticsStreamEventAnalyticsEventWrapper},
|
|
288
|
+
* extracting the user ID for convenient access by listeners.
|
|
289
|
+
*
|
|
290
|
+
* @param event - the analytics event with optional user context
|
|
291
|
+
* @param type - the stream event type classification; defaults to `Event`
|
|
292
|
+
* @returns a wrapper combining the event, type, user, and extracted userId
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* const wrapper = dbxAnalyticsStreamEventAnalyticsEventWrapper(
|
|
297
|
+
* { name: 'Button Clicked', user: { user: 'uid_123' } },
|
|
298
|
+
* DbxAnalyticsStreamEventType.Event
|
|
299
|
+
* );
|
|
300
|
+
* // wrapper.userId === 'uid_123'
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
101
303
|
declare function dbxAnalyticsStreamEventAnalyticsEventWrapper(event: DbxUserAnalyticsEvent, type?: DbxAnalyticsStreamEventType): {
|
|
102
304
|
event: DbxUserAnalyticsEvent;
|
|
103
305
|
type: DbxAnalyticsStreamEventType;
|
|
@@ -105,7 +307,27 @@ declare function dbxAnalyticsStreamEventAnalyticsEventWrapper(event: DbxUserAnal
|
|
|
105
307
|
userId: string | undefined;
|
|
106
308
|
};
|
|
107
309
|
/**
|
|
108
|
-
*
|
|
310
|
+
* Central analytics service that emits typed analytics events for consumption by registered listeners.
|
|
311
|
+
*
|
|
312
|
+
* Acts as both the event emitter (components call methods like {@link sendEventData}, {@link sendPageView})
|
|
313
|
+
* and the event stream source (listeners subscribe to {@link events$}).
|
|
314
|
+
*
|
|
315
|
+
* In production mode, registered {@link DbxAnalyticsServiceListener} instances (e.g., Segment) receive all events.
|
|
316
|
+
* In non-production mode, events are logged to the console for debugging.
|
|
317
|
+
*
|
|
318
|
+
* Provided via {@link provideDbxAnalyticsService} with a {@link DbxAnalyticsServiceConfiguration} factory.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* // Send a custom event from a component
|
|
323
|
+
* const analytics = inject(DbxAnalyticsService);
|
|
324
|
+
* analytics.sendEventData('Interview Started', { candidateId: 'abc123' });
|
|
325
|
+
*
|
|
326
|
+
* // Send a page view on route transitions
|
|
327
|
+
* transitionService.onSuccess({}, () => {
|
|
328
|
+
* analytics.sendPageView();
|
|
329
|
+
* });
|
|
330
|
+
* ```
|
|
109
331
|
*/
|
|
110
332
|
declare class DbxAnalyticsService implements DbxAnalyticsEventStreamService, DbxAnalyticsEventEmitterService, Destroyable {
|
|
111
333
|
private readonly _config;
|
|
@@ -122,20 +344,98 @@ declare class DbxAnalyticsService implements DbxAnalyticsEventStreamService, Dbx
|
|
|
122
344
|
private _loggerSub;
|
|
123
345
|
constructor();
|
|
124
346
|
/**
|
|
125
|
-
* Sets the user directly,
|
|
347
|
+
* Sets the analytics user directly, overriding any configured {@link DbxAnalyticsUserSource}.
|
|
348
|
+
*
|
|
349
|
+
* Pass `undefined` to clear the current user (e.g., on logout).
|
|
350
|
+
*
|
|
351
|
+
* @param user - the user to identify, or undefined to clear
|
|
126
352
|
*/
|
|
127
353
|
setUser(user: Maybe<DbxAnalyticsUser>): void;
|
|
354
|
+
/**
|
|
355
|
+
* Sets the reactive user source that automatically updates the analytics user as auth state changes.
|
|
356
|
+
*
|
|
357
|
+
* @param source - the user source providing an observable of the current analytics user
|
|
358
|
+
*/
|
|
128
359
|
setUserSource(source: DbxAnalyticsUserSource): void;
|
|
129
360
|
/**
|
|
130
|
-
*
|
|
361
|
+
* Emits a new user registration event, typically sent once after account creation.
|
|
362
|
+
*
|
|
363
|
+
* @param user - the newly registered user
|
|
364
|
+
* @param data - registration-specific data including the signup method
|
|
131
365
|
*/
|
|
132
366
|
sendNewUserEvent(user: DbxAnalyticsUser, data: NewUserAnalyticsEventData): void;
|
|
367
|
+
/**
|
|
368
|
+
* Emits a user login event, identifying the user in analytics providers.
|
|
369
|
+
*
|
|
370
|
+
* @param user - the user who logged in
|
|
371
|
+
* @param data - optional additional event data
|
|
372
|
+
*/
|
|
133
373
|
sendUserLoginEvent(user: DbxAnalyticsUser, data?: DbxAnalyticsEventData): void;
|
|
374
|
+
/**
|
|
375
|
+
* Emits a user logout event and optionally clears the current analytics user.
|
|
376
|
+
*
|
|
377
|
+
* @param data - optional additional event data
|
|
378
|
+
* @param clearUser - whether to reset the analytics user identity; defaults to `true`
|
|
379
|
+
*/
|
|
134
380
|
sendUserLogoutEvent(data?: DbxAnalyticsEventData, clearUser?: boolean): void;
|
|
381
|
+
/**
|
|
382
|
+
* Emits a user properties update event, used to sync user traits to analytics providers.
|
|
383
|
+
*
|
|
384
|
+
* @param user - the user whose properties are being updated
|
|
385
|
+
* @param data - optional additional event data
|
|
386
|
+
*/
|
|
135
387
|
sendUserPropertiesEvent(user: DbxAnalyticsUser, data?: DbxAnalyticsEventData): void;
|
|
136
|
-
|
|
388
|
+
/**
|
|
389
|
+
* @deprecated When sending an event with no data, use {@link sendEventType} instead.
|
|
390
|
+
*/
|
|
391
|
+
sendEventData(name: DbxAnalyticsEventName): void;
|
|
392
|
+
/**
|
|
393
|
+
* Sends a named analytics event with a data payload.
|
|
394
|
+
*
|
|
395
|
+
* This is the primary method for tracking custom events with associated properties.
|
|
396
|
+
*
|
|
397
|
+
* @param name - the event name (e.g., `'Interview Ended'`)
|
|
398
|
+
* @param data - key-value data attached to the event
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* analytics.sendEventData('Interview Ended', {
|
|
403
|
+
* seconds: 120,
|
|
404
|
+
* endedDueToTime: 'true'
|
|
405
|
+
* });
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
sendEventData(name: DbxAnalyticsEventName, data: DbxAnalyticsEventData): void;
|
|
409
|
+
/**
|
|
410
|
+
* Sends a named event with no additional data, useful for simple occurrence tracking.
|
|
411
|
+
*
|
|
412
|
+
* @param eventType - the event name to track
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```ts
|
|
416
|
+
* analytics.sendEventType('Finish Account Setup');
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
137
419
|
sendEventType(eventType: DbxAnalyticsEventName): void;
|
|
420
|
+
/**
|
|
421
|
+
* Sends a fully constructed analytics event object.
|
|
422
|
+
*
|
|
423
|
+
* @param event - the event containing name, optional value, and data
|
|
424
|
+
*/
|
|
138
425
|
sendEvent(event: DbxAnalyticsEvent): void;
|
|
426
|
+
/**
|
|
427
|
+
* Sends a page view event, typically called on successful route transitions.
|
|
428
|
+
*
|
|
429
|
+
* @param page - optional page name/path override; if omitted, the provider determines the current page
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* // In a router config function
|
|
434
|
+
* transitionService.onSuccess({}, () => {
|
|
435
|
+
* analyticsService.sendPageView();
|
|
436
|
+
* });
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
139
439
|
sendPageView(page?: string): void;
|
|
140
440
|
/**
|
|
141
441
|
* Sends the next event.
|
|
@@ -153,16 +453,55 @@ declare class DbxAnalyticsService implements DbxAnalyticsEventStreamService, Dbx
|
|
|
153
453
|
}
|
|
154
454
|
|
|
155
455
|
/**
|
|
156
|
-
* DbxActionAnalyticsDirective
|
|
456
|
+
* Configuration for {@link DbxActionAnalyticsDirective} that maps action lifecycle events to analytics calls.
|
|
457
|
+
*
|
|
458
|
+
* Each callback receives the {@link DbxAnalyticsService} and relevant action data, allowing you to
|
|
459
|
+
* send targeted analytics events at each stage of an action's lifecycle (trigger, ready, success, error).
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```ts
|
|
463
|
+
* // In a component, define analytics config for a form submit action
|
|
464
|
+
* readonly submitAnalytics: DbxActionAnalyticsConfig<MyFormValue, MyResult> = {
|
|
465
|
+
* onReady: (service, value) => {
|
|
466
|
+
* service.sendEventData('Form Submitted', { formType: 'onboard' });
|
|
467
|
+
* },
|
|
468
|
+
* onSuccess: (service, result, value) => {
|
|
469
|
+
* service.sendEventType('Onboarding Complete');
|
|
470
|
+
* },
|
|
471
|
+
* onError: (service, error) => {
|
|
472
|
+
* service.sendEventData('Form Submit Failed', { code: error?.code ?? 'unknown' });
|
|
473
|
+
* }
|
|
474
|
+
* };
|
|
475
|
+
*
|
|
476
|
+
* // In the template
|
|
477
|
+
* // <button dbxAction [dbxActionAnalytics]="submitAnalytics">Submit</button>
|
|
478
|
+
* ```
|
|
157
479
|
*/
|
|
158
480
|
interface DbxActionAnalyticsConfig<T = unknown, O = unknown> {
|
|
481
|
+
/** Called when the action is triggered (button pressed). */
|
|
159
482
|
readonly onTriggered?: (service: DbxAnalyticsService) => void;
|
|
483
|
+
/** Called when the action value is ready and about to be processed. */
|
|
160
484
|
readonly onReady?: (service: DbxAnalyticsService, value: T) => void;
|
|
485
|
+
/** Called when the action completes successfully. */
|
|
161
486
|
readonly onSuccess?: (service: DbxAnalyticsService, result: Maybe<O>, value: T) => void;
|
|
487
|
+
/** Called when the action encounters an error. */
|
|
162
488
|
readonly onError?: (service: DbxAnalyticsService, error: Maybe<ReadableError>) => void;
|
|
163
489
|
}
|
|
164
490
|
/**
|
|
165
|
-
*
|
|
491
|
+
* Standalone directive that listens to a host {@link DbxActionDirective} and fires analytics events
|
|
492
|
+
* based on the action's lifecycle (triggered, ready, success, error).
|
|
493
|
+
*
|
|
494
|
+
* Attach to any element that has a `dbxAction` directive and pass a {@link DbxActionAnalyticsConfig}
|
|
495
|
+
* to define which events to send at each lifecycle stage.
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```html
|
|
499
|
+
* <button dbxAction
|
|
500
|
+
* [dbxActionHandler]="handleSave"
|
|
501
|
+
* [dbxActionAnalytics]="saveAnalytics">
|
|
502
|
+
* Save
|
|
503
|
+
* </button>
|
|
504
|
+
* ```
|
|
166
505
|
*/
|
|
167
506
|
declare class DbxActionAnalyticsDirective<T, O> {
|
|
168
507
|
readonly source: DbxActionContextStoreSourceInstance<T, O>;
|
|
@@ -183,37 +522,120 @@ declare class DbxAnalyticsActionModule {
|
|
|
183
522
|
static ɵinj: i0.ɵɵInjectorDeclaration<DbxAnalyticsActionModule>;
|
|
184
523
|
}
|
|
185
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Factory function that creates a {@link DbxAnalyticsServiceConfiguration} using the Angular injector.
|
|
527
|
+
*
|
|
528
|
+
* Used by {@link provideDbxAnalyticsService} to defer configuration resolution to runtime.
|
|
529
|
+
*/
|
|
186
530
|
type DbxAnalyticsServiceConfigurationFactory = (injector: Injector) => DbxAnalyticsServiceConfiguration;
|
|
187
531
|
/**
|
|
188
|
-
* Configuration for provideDbxAnalyticsService
|
|
532
|
+
* Configuration for {@link provideDbxAnalyticsService}.
|
|
189
533
|
*/
|
|
190
534
|
interface ProvideDbxAnalyticsConfig {
|
|
191
535
|
readonly dbxAnalyticsServiceConfigurationFactory: DbxAnalyticsServiceConfigurationFactory;
|
|
192
536
|
}
|
|
193
537
|
/**
|
|
194
|
-
* Creates
|
|
538
|
+
* Creates Angular environment providers that register {@link DbxAnalyticsService} and its configuration.
|
|
195
539
|
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
540
|
+
* Call this in your application's `providers` array to set up analytics with a custom configuration factory
|
|
541
|
+
* that resolves listeners, user sources, and environment flags at runtime.
|
|
542
|
+
*
|
|
543
|
+
* @param config - contains the factory function that produces a {@link DbxAnalyticsServiceConfiguration}
|
|
544
|
+
* @returns environment providers for the analytics service
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* // In app.config.ts
|
|
549
|
+
* export const appConfig: ApplicationConfig = {
|
|
550
|
+
* providers: [
|
|
551
|
+
* provideDbxAnalyticsService({
|
|
552
|
+
* dbxAnalyticsServiceConfigurationFactory: (injector: Injector) => ({
|
|
553
|
+
* isProduction: environment.production,
|
|
554
|
+
* logEvents: !environment.production,
|
|
555
|
+
* listeners: [injector.get(DbxAnalyticsSegmentServiceListener)],
|
|
556
|
+
* userSource: injector.get(DbxFirebaseAnalyticsUserSource)
|
|
557
|
+
* })
|
|
558
|
+
* })
|
|
559
|
+
* ]
|
|
560
|
+
* };
|
|
561
|
+
* ```
|
|
198
562
|
*/
|
|
199
563
|
declare function provideDbxAnalyticsService(config: ProvideDbxAnalyticsConfig): EnvironmentProviders;
|
|
200
564
|
|
|
201
565
|
/**
|
|
202
|
-
*
|
|
566
|
+
* Analytics listener that forwards {@link DbxAnalyticsStreamEvent} events to the Segment SDK.
|
|
567
|
+
*
|
|
568
|
+
* Automatically maps event types to the appropriate Segment methods:
|
|
569
|
+
* - {@link DbxAnalyticsStreamEventType.Event} / {@link DbxAnalyticsStreamEventType.UserLoginEvent} -> `track()`
|
|
570
|
+
* - {@link DbxAnalyticsStreamEventType.UserChange} / {@link DbxAnalyticsStreamEventType.NewUserEvent} -> `identify()`
|
|
571
|
+
* - {@link DbxAnalyticsStreamEventType.UserLogoutEvent} -> `reset()`
|
|
572
|
+
* - {@link DbxAnalyticsStreamEventType.PageView} -> `page()`
|
|
573
|
+
*
|
|
574
|
+
* Events are only sent when the Segment configuration is marked as `active`.
|
|
575
|
+
* Provided at root level and registered as a listener via {@link DbxAnalyticsServiceConfiguration.listeners}.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```ts
|
|
579
|
+
* // Register in analytics configuration factory
|
|
580
|
+
* function analyticsConfigFactory(injector: Injector): DbxAnalyticsServiceConfiguration {
|
|
581
|
+
* const segmentListener = injector.get(DbxAnalyticsSegmentServiceListener);
|
|
582
|
+
* return {
|
|
583
|
+
* isProduction: true,
|
|
584
|
+
* listeners: [segmentListener]
|
|
585
|
+
* };
|
|
586
|
+
* }
|
|
587
|
+
* ```
|
|
203
588
|
*/
|
|
204
589
|
declare class DbxAnalyticsSegmentServiceListener extends AbstractDbxAnalyticsServiceListener {
|
|
205
590
|
private readonly _segmentApi;
|
|
206
591
|
constructor();
|
|
592
|
+
/**
|
|
593
|
+
* Subscribes to the Segment API service and analytics event stream, forwarding events to the Segment SDK.
|
|
594
|
+
*
|
|
595
|
+
* Events are only sent when the Segment configuration is marked as active.
|
|
596
|
+
*/
|
|
207
597
|
protected _initializeServiceSubscription(): rxjs.Subscription;
|
|
598
|
+
/**
|
|
599
|
+
* Routes an analytics stream event to the appropriate Segment API method based on event type.
|
|
600
|
+
*
|
|
601
|
+
* @param api - The Segment analytics SDK instance
|
|
602
|
+
* @param streamEvent - The analytics event to process
|
|
603
|
+
*/
|
|
208
604
|
protected handleStreamEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent): void;
|
|
605
|
+
/**
|
|
606
|
+
* Handles a new user registration event by identifying the user in Segment.
|
|
607
|
+
*
|
|
608
|
+
* @param api - The Segment analytics SDK instance
|
|
609
|
+
* @param streamEvent - The event containing the new user data
|
|
610
|
+
*/
|
|
209
611
|
protected updateWithNewUserEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent): void;
|
|
612
|
+
/**
|
|
613
|
+
* Sends a track event to Segment with the event name, value, and additional data properties.
|
|
614
|
+
*
|
|
615
|
+
* @param api - The Segment analytics SDK instance
|
|
616
|
+
* @param streamEvent - The analytics event containing name, value, and data
|
|
617
|
+
* @param name - Optional override for the event name
|
|
618
|
+
*/
|
|
210
619
|
protected updateWithEvent(api: SegmentAnalytics.AnalyticsJS, streamEvent: DbxAnalyticsStreamEvent, name?: string): void;
|
|
211
620
|
private changeUser;
|
|
212
621
|
static ɵfac: i0.ɵɵFactoryDeclaration<DbxAnalyticsSegmentServiceListener, never>;
|
|
213
622
|
static ɵprov: i0.ɵɵInjectableDeclaration<DbxAnalyticsSegmentServiceListener>;
|
|
214
623
|
}
|
|
215
624
|
|
|
625
|
+
/**
|
|
626
|
+
* Injection token for optionally preloading the Segment analytics script.
|
|
627
|
+
*/
|
|
216
628
|
declare const PRELOAD_SEGMENT_TOKEN: InjectionToken<string>;
|
|
629
|
+
/**
|
|
630
|
+
* Configuration for the Segment analytics integration.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* const config = new DbxAnalyticsSegmentApiServiceConfig('your-segment-write-key');
|
|
635
|
+
* config.active = environment.production;
|
|
636
|
+
* config.logging = !environment.production;
|
|
637
|
+
* ```
|
|
638
|
+
*/
|
|
217
639
|
declare class DbxAnalyticsSegmentApiServiceConfig {
|
|
218
640
|
writeKey: string;
|
|
219
641
|
logging: boolean;
|
|
@@ -221,9 +643,26 @@ declare class DbxAnalyticsSegmentApiServiceConfig {
|
|
|
221
643
|
constructor(writeKey: string);
|
|
222
644
|
}
|
|
223
645
|
/**
|
|
224
|
-
*
|
|
646
|
+
* Service that manages the async loading and initialization of the Segment analytics SDK from `window.analytics`.
|
|
225
647
|
*
|
|
226
|
-
*
|
|
648
|
+
* Polls for the Segment snippet to be invoked, then calls `analytics.load()` with the configured write key.
|
|
649
|
+
* Once Segment reports ready, the resolved SDK instance is available via the inherited `service$` observable.
|
|
650
|
+
*
|
|
651
|
+
* Requires the Segment analytics snippet to be included in `index.html`.
|
|
652
|
+
*
|
|
653
|
+
* Provided via {@link provideDbxAnalyticsSegmentApiService}.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* // In app.config.ts
|
|
658
|
+
* provideDbxAnalyticsSegmentApiService({
|
|
659
|
+
* dbxAnalyticsSegmentApiServiceConfigFactory: (injector) => {
|
|
660
|
+
* const config = new DbxAnalyticsSegmentApiServiceConfig(environment.analytics.segment);
|
|
661
|
+
* config.active = environment.production;
|
|
662
|
+
* return config;
|
|
663
|
+
* }
|
|
664
|
+
* })
|
|
665
|
+
* ```
|
|
227
666
|
*/
|
|
228
667
|
declare class DbxAnalyticsSegmentApiService extends AbstractAsyncWindowLoadedService<SegmentAnalytics.AnalyticsJS> {
|
|
229
668
|
private readonly _config;
|
|
@@ -237,19 +676,51 @@ declare class DbxAnalyticsSegmentApiService extends AbstractAsyncWindowLoadedSer
|
|
|
237
676
|
static ɵprov: i0.ɵɵInjectableDeclaration<DbxAnalyticsSegmentApiService>;
|
|
238
677
|
}
|
|
239
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Factory function that creates a {@link DbxAnalyticsSegmentApiServiceConfig} using the Angular injector.
|
|
681
|
+
*
|
|
682
|
+
* Used by {@link provideDbxAnalyticsSegmentApiService} to defer Segment configuration to runtime.
|
|
683
|
+
*/
|
|
240
684
|
type DbxAnalyticsSegmentApiServiceConfigFactory = (injector: Injector) => DbxAnalyticsSegmentApiServiceConfig;
|
|
241
685
|
/**
|
|
242
|
-
* Configuration for provideDbxAnalyticsSegmentApiService
|
|
686
|
+
* Configuration for {@link provideDbxAnalyticsSegmentApiService}.
|
|
243
687
|
*/
|
|
244
688
|
interface ProvideDbxAnalyticsSegmentModuleConfig {
|
|
689
|
+
/** Whether to preload the Segment script token. */
|
|
245
690
|
readonly preloadSegmentToken?: boolean;
|
|
691
|
+
/** Factory function that produces the Segment API service configuration. */
|
|
246
692
|
readonly dbxAnalyticsSegmentApiServiceConfigFactory: DbxAnalyticsSegmentApiServiceConfigFactory;
|
|
247
693
|
}
|
|
248
694
|
/**
|
|
249
|
-
* Creates
|
|
695
|
+
* Creates Angular environment providers that register {@link DbxAnalyticsSegmentApiService} for Segment analytics integration.
|
|
696
|
+
*
|
|
697
|
+
* Use alongside {@link provideDbxAnalyticsService} to wire Segment as an analytics listener.
|
|
698
|
+
*
|
|
699
|
+
* @param config - Segment-specific configuration including the write key factory
|
|
700
|
+
* @returns environment providers for Segment analytics
|
|
250
701
|
*
|
|
251
|
-
* @
|
|
252
|
-
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```ts
|
|
704
|
+
* // In app.config.ts
|
|
705
|
+
* export const appConfig: ApplicationConfig = {
|
|
706
|
+
* providers: [
|
|
707
|
+
* provideDbxAnalyticsSegmentApiService({
|
|
708
|
+
* dbxAnalyticsSegmentApiServiceConfigFactory: (injector) => {
|
|
709
|
+
* const config = new DbxAnalyticsSegmentApiServiceConfig(environment.analytics.segment);
|
|
710
|
+
* config.active = environment.production;
|
|
711
|
+
* config.logging = !environment.production;
|
|
712
|
+
* return config;
|
|
713
|
+
* }
|
|
714
|
+
* }),
|
|
715
|
+
* provideDbxAnalyticsService({
|
|
716
|
+
* dbxAnalyticsServiceConfigurationFactory: (injector) => ({
|
|
717
|
+
* isProduction: environment.production,
|
|
718
|
+
* listeners: [injector.get(DbxAnalyticsSegmentServiceListener)]
|
|
719
|
+
* })
|
|
720
|
+
* })
|
|
721
|
+
* ]
|
|
722
|
+
* };
|
|
723
|
+
* ```
|
|
253
724
|
*/
|
|
254
725
|
declare function provideDbxAnalyticsSegmentApiService(config: ProvideDbxAnalyticsSegmentModuleConfig): EnvironmentProviders;
|
|
255
726
|
|