@funnelsgrove/analytics 0.1.18 → 0.1.20
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.
|
@@ -44,6 +44,7 @@ export type PublicSdkConversionCallbackInput = {
|
|
|
44
44
|
occurredAt?: string;
|
|
45
45
|
stepId?: string;
|
|
46
46
|
stepName?: string;
|
|
47
|
+
stepType?: string;
|
|
47
48
|
metadata?: Record<string, unknown>;
|
|
48
49
|
featureFlags?: Record<string, string | null | undefined>;
|
|
49
50
|
};
|
|
@@ -86,6 +87,8 @@ export declare class PublicAnalyticsSdkService {
|
|
|
86
87
|
trackCheckoutStarted(input: PublicSdkConversionCallbackInput): string | null;
|
|
87
88
|
trackPaymentInfoSubmitted(input: PublicSdkConversionCallbackInput): string | null;
|
|
88
89
|
trackCheckoutCompleted(input: PublicSdkConversionCallbackInput): string | null;
|
|
90
|
+
trackPaymentCheckoutSucceeded(input: PublicSdkConversionCallbackInput): string | null;
|
|
91
|
+
trackPaymentCheckoutReturned(input: PublicSdkConversionCallbackInput): string | null;
|
|
89
92
|
flush(): Promise<number>;
|
|
90
93
|
private ensureUserId;
|
|
91
94
|
private resolveBootstrapUserId;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildMainApiUrl, buildSdkHeaders, FUNNEL_ID, FUNNEL_VERSION_ID, getFunnelSdkPublishableKey, hasPostHogRuntimeConfig, POSTHOG_API_HOST, POSTHOG_PROJECT_API_KEY, PROJECT_ID,
|
|
1
|
+
import { buildMainApiUrl, buildSdkHeaders, FUNNEL_ID, FUNNEL_VERSION_ID, getFunnelSdkPublishableKey, hasPostHogRuntimeConfig, POSTHOG_API_HOST, POSTHOG_PROJECT_API_KEY, PROJECT_ID, } from './runtime-api.config.js';
|
|
2
2
|
import { canUseDom, getOrCreateUserId, persistUserId, readStoredUserId, } from './sdk-user-id.storage.js';
|
|
3
3
|
import { mapAnalyticsEventToMetaPixelEvent, metaPixelService, } from './meta-pixel.service.js';
|
|
4
4
|
import { googleTagService, mapAnalyticsEventToGoogleTagEvent, } from './google-tag.service.js';
|
|
@@ -129,7 +129,6 @@ const normalizeFeatureFlags = (featureFlags) => {
|
|
|
129
129
|
const buildFeatureFlagProperties = (featureFlags) => {
|
|
130
130
|
return Object.fromEntries(Object.entries(featureFlags).map(([key, value]) => [`$feature/${key}`, value]));
|
|
131
131
|
};
|
|
132
|
-
const isRuntimeTestMode = () => STRIPE_ACTIVE_MODE === 'test';
|
|
133
132
|
const buildEventMetadata = (eventType, metadata) => {
|
|
134
133
|
if (eventType !== 'checkout_completed') {
|
|
135
134
|
return metadata;
|
|
@@ -327,6 +326,7 @@ export class PublicAnalyticsSdkService {
|
|
|
327
326
|
occurredAt: input.occurredAt,
|
|
328
327
|
stepId: input.stepId,
|
|
329
328
|
stepName: input.stepName,
|
|
329
|
+
stepType: input.stepType,
|
|
330
330
|
metadata: input.metadata,
|
|
331
331
|
featureFlags: input.featureFlags,
|
|
332
332
|
});
|
|
@@ -338,6 +338,7 @@ export class PublicAnalyticsSdkService {
|
|
|
338
338
|
occurredAt: input.occurredAt,
|
|
339
339
|
stepId: input.stepId,
|
|
340
340
|
stepName: input.stepName,
|
|
341
|
+
stepType: input.stepType,
|
|
341
342
|
metadata: input.metadata,
|
|
342
343
|
featureFlags: input.featureFlags,
|
|
343
344
|
});
|
|
@@ -349,6 +350,7 @@ export class PublicAnalyticsSdkService {
|
|
|
349
350
|
occurredAt: input.occurredAt,
|
|
350
351
|
stepId: input.stepId,
|
|
351
352
|
stepName: input.stepName,
|
|
353
|
+
stepType: input.stepType,
|
|
352
354
|
metadata: input.metadata,
|
|
353
355
|
featureFlags: input.featureFlags,
|
|
354
356
|
});
|
|
@@ -360,6 +362,7 @@ export class PublicAnalyticsSdkService {
|
|
|
360
362
|
occurredAt: input.occurredAt,
|
|
361
363
|
stepId: input.stepId,
|
|
362
364
|
stepName: input.stepName,
|
|
365
|
+
stepType: input.stepType,
|
|
363
366
|
metadata: input.metadata,
|
|
364
367
|
featureFlags: input.featureFlags,
|
|
365
368
|
});
|
|
@@ -371,6 +374,7 @@ export class PublicAnalyticsSdkService {
|
|
|
371
374
|
occurredAt: input.occurredAt,
|
|
372
375
|
stepId: input.stepId,
|
|
373
376
|
stepName: input.stepName,
|
|
377
|
+
stepType: input.stepType,
|
|
374
378
|
metadata: input.metadata,
|
|
375
379
|
featureFlags: input.featureFlags,
|
|
376
380
|
});
|
|
@@ -382,6 +386,7 @@ export class PublicAnalyticsSdkService {
|
|
|
382
386
|
occurredAt: input.occurredAt,
|
|
383
387
|
stepId: input.stepId,
|
|
384
388
|
stepName: input.stepName,
|
|
389
|
+
stepType: input.stepType,
|
|
385
390
|
metadata: input.metadata,
|
|
386
391
|
featureFlags: input.featureFlags,
|
|
387
392
|
});
|
|
@@ -393,6 +398,7 @@ export class PublicAnalyticsSdkService {
|
|
|
393
398
|
occurredAt: input.occurredAt,
|
|
394
399
|
stepId: input.stepId,
|
|
395
400
|
stepName: input.stepName,
|
|
401
|
+
stepType: input.stepType,
|
|
396
402
|
metadata: input.metadata,
|
|
397
403
|
featureFlags: input.featureFlags,
|
|
398
404
|
});
|
|
@@ -404,6 +410,31 @@ export class PublicAnalyticsSdkService {
|
|
|
404
410
|
occurredAt: input.occurredAt,
|
|
405
411
|
stepId: input.stepId,
|
|
406
412
|
stepName: input.stepName,
|
|
413
|
+
stepType: input.stepType,
|
|
414
|
+
metadata: input.metadata,
|
|
415
|
+
featureFlags: input.featureFlags,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
trackPaymentCheckoutSucceeded(input) {
|
|
419
|
+
return this.track({
|
|
420
|
+
eventType: 'payment_checkout_succeeded',
|
|
421
|
+
eventId: input.eventId,
|
|
422
|
+
occurredAt: input.occurredAt,
|
|
423
|
+
stepId: input.stepId,
|
|
424
|
+
stepName: input.stepName,
|
|
425
|
+
stepType: input.stepType,
|
|
426
|
+
metadata: input.metadata,
|
|
427
|
+
featureFlags: input.featureFlags,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
trackPaymentCheckoutReturned(input) {
|
|
431
|
+
return this.track({
|
|
432
|
+
eventType: 'payment_checkout_returned',
|
|
433
|
+
eventId: input.eventId,
|
|
434
|
+
occurredAt: input.occurredAt,
|
|
435
|
+
stepId: input.stepId,
|
|
436
|
+
stepName: input.stepName,
|
|
437
|
+
stepType: input.stepType,
|
|
407
438
|
metadata: input.metadata,
|
|
408
439
|
featureFlags: input.featureFlags,
|
|
409
440
|
});
|
|
@@ -484,13 +515,14 @@ export class PublicAnalyticsSdkService {
|
|
|
484
515
|
if (!getFunnelSdkPublishableKey() || !hasPostHogRuntimeConfig()) {
|
|
485
516
|
return true;
|
|
486
517
|
}
|
|
518
|
+
const analyticsEnvironment = resolveAnalyticsEnvironment();
|
|
487
519
|
const batch = events.map((event) => {
|
|
488
520
|
var _a, _b;
|
|
489
521
|
return ({
|
|
490
522
|
event: toPostHogEventName(event.eventType),
|
|
491
523
|
properties: buildDefinedRecord(Object.assign(Object.assign({ distinct_id: this.ensureUserId(), $groups: {
|
|
492
524
|
project: PROJECT_ID,
|
|
493
|
-
}, $insert_id: event.eventId, project_id: PROJECT_ID, funnel_id: FUNNEL_ID || undefined, funnel_version_id: FUNNEL_VERSION_ID || undefined, environment:
|
|
525
|
+
}, $insert_id: event.eventId, project_id: PROJECT_ID, funnel_id: FUNNEL_ID || undefined, funnel_version_id: FUNNEL_VERSION_ID || undefined, environment: analyticsEnvironment, test: analyticsEnvironment === 'test' || undefined, step_id: event.stepId || undefined, step_name: event.stepName || undefined, step_type: event.stepType || undefined, started_at: event.startedAt || undefined, ended_at: event.endedAt || undefined, duration_ms: (_a = event.durationMs) !== null && _a !== void 0 ? _a : undefined, engagement_threshold_ms: (_b = event.engagementThresholdMs) !== null && _b !== void 0 ? _b : undefined, event_source: 'client' }, buildFeatureFlagProperties(event.featureFlags)), { selected: Object.keys(event.selected).length > 0 ? event.selected : undefined, payload: Object.keys(event.payload).length > 0 ? event.payload : undefined, context: Object.keys(event.context).length > 0 ? event.context : undefined, metadata: Object.keys(event.metadata).length > 0 ? event.metadata : undefined })),
|
|
494
526
|
timestamp: event.occurredAt,
|
|
495
527
|
});
|
|
496
528
|
});
|