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