@funnelsgrove/analytics 0.1.20 → 0.1.22

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.
@@ -1,5 +1,7 @@
1
1
  export type PublicSdkTrackEventInput = {
2
2
  eventType: string;
3
+ userId?: string;
4
+ environment?: PublicSdkAnalyticsEnvironment;
3
5
  eventId?: string;
4
6
  occurredAt?: string;
5
7
  stepId?: string;
@@ -14,6 +16,8 @@ export type PublicSdkTrackEventInput = {
14
16
  featureFlags?: Record<string, string | null | undefined>;
15
17
  };
16
18
  export type PublicSdkStepStartInput = {
19
+ userId?: string;
20
+ environment?: PublicSdkAnalyticsEnvironment;
17
21
  stepId: string;
18
22
  stepName: string;
19
23
  stepType?: string;
@@ -21,6 +25,8 @@ export type PublicSdkStepStartInput = {
21
25
  featureFlags?: Record<string, string | null | undefined>;
22
26
  };
23
27
  export type PublicSdkStepEndInput = {
28
+ userId?: string;
29
+ environment?: PublicSdkAnalyticsEnvironment;
24
30
  stepId: string;
25
31
  stepName: string;
26
32
  stepType?: string;
@@ -30,6 +36,8 @@ export type PublicSdkStepEndInput = {
30
36
  featureFlags?: Record<string, string | null | undefined>;
31
37
  };
32
38
  export type PublicSdkStepEngagedInput = {
39
+ userId?: string;
40
+ environment?: PublicSdkAnalyticsEnvironment;
33
41
  stepId: string;
34
42
  stepName: string;
35
43
  stepType?: string;
@@ -40,6 +48,8 @@ export type PublicSdkStepEngagedInput = {
40
48
  featureFlags?: Record<string, string | null | undefined>;
41
49
  };
42
50
  export type PublicSdkConversionCallbackInput = {
51
+ userId?: string;
52
+ environment?: PublicSdkAnalyticsEnvironment;
43
53
  eventId?: string;
44
54
  occurredAt?: string;
45
55
  stepId?: string;
@@ -58,6 +68,7 @@ export type PublicAnalyticsSdkOptions = {
58
68
  batchSize: number;
59
69
  flushIntervalMs: number;
60
70
  };
71
+ export type PublicSdkAnalyticsEnvironment = 'test' | 'live';
61
72
  export declare class PublicAnalyticsSdkService {
62
73
  private readonly options;
63
74
  private readonly eventQueue;
@@ -250,6 +250,8 @@ export class PublicAnalyticsSdkService {
250
250
  }
251
251
  const envelope = {
252
252
  eventType,
253
+ userId: asString(event.userId),
254
+ environment: normalizeEnvironment(event.environment),
253
255
  eventId,
254
256
  occurredAt: toIsoOrNow(event.occurredAt),
255
257
  stepId: asString(event.stepId),
@@ -276,6 +278,8 @@ export class PublicAnalyticsSdkService {
276
278
  trackStepStarted(input) {
277
279
  return this.track({
278
280
  eventType: 'step_start',
281
+ userId: input.userId,
282
+ environment: input.environment,
279
283
  stepId: input.stepId,
280
284
  stepName: input.stepName,
281
285
  stepType: input.stepType,
@@ -290,6 +294,8 @@ export class PublicAnalyticsSdkService {
290
294
  const endedAt = asString(input.endedAt);
291
295
  return this.track({
292
296
  eventType: 'step_end',
297
+ userId: input.userId,
298
+ environment: input.environment,
293
299
  stepId: input.stepId,
294
300
  stepName: input.stepName,
295
301
  stepType: input.stepType,
@@ -306,6 +312,8 @@ export class PublicAnalyticsSdkService {
306
312
  trackStepEngaged(input) {
307
313
  return this.track({
308
314
  eventType: 'step_engaged',
315
+ userId: input.userId,
316
+ environment: input.environment,
309
317
  stepId: input.stepId,
310
318
  stepName: input.stepName,
311
319
  stepType: input.stepType,
@@ -322,6 +330,8 @@ export class PublicAnalyticsSdkService {
322
330
  trackFunnelStarted(input) {
323
331
  return this.track({
324
332
  eventType: 'funnel_start',
333
+ userId: input.userId,
334
+ environment: input.environment,
325
335
  eventId: input.eventId,
326
336
  occurredAt: input.occurredAt,
327
337
  stepId: input.stepId,
@@ -334,6 +344,8 @@ export class PublicAnalyticsSdkService {
334
344
  trackFirstStepClicked(input) {
335
345
  return this.track({
336
346
  eventType: 'first_step_clicked',
347
+ userId: input.userId,
348
+ environment: input.environment,
337
349
  eventId: input.eventId,
338
350
  occurredAt: input.occurredAt,
339
351
  stepId: input.stepId,
@@ -346,6 +358,8 @@ export class PublicAnalyticsSdkService {
346
358
  trackFirstStepViewed(input) {
347
359
  return this.track({
348
360
  eventType: 'first_step_viewed',
361
+ userId: input.userId,
362
+ environment: input.environment,
349
363
  eventId: input.eventId,
350
364
  occurredAt: input.occurredAt,
351
365
  stepId: input.stepId,
@@ -358,6 +372,8 @@ export class PublicAnalyticsSdkService {
358
372
  trackLead(input) {
359
373
  return this.track({
360
374
  eventType: 'email_captured',
375
+ userId: input.userId,
376
+ environment: input.environment,
361
377
  eventId: input.eventId,
362
378
  occurredAt: input.occurredAt,
363
379
  stepId: input.stepId,
@@ -370,6 +386,8 @@ export class PublicAnalyticsSdkService {
370
386
  trackFunnelCompleted(input) {
371
387
  return this.track({
372
388
  eventType: 'funnel_completed',
389
+ userId: input.userId,
390
+ environment: input.environment,
373
391
  eventId: input.eventId,
374
392
  occurredAt: input.occurredAt,
375
393
  stepId: input.stepId,
@@ -382,6 +400,8 @@ export class PublicAnalyticsSdkService {
382
400
  trackCheckoutStarted(input) {
383
401
  return this.track({
384
402
  eventType: 'checkout_started',
403
+ userId: input.userId,
404
+ environment: input.environment,
385
405
  eventId: input.eventId,
386
406
  occurredAt: input.occurredAt,
387
407
  stepId: input.stepId,
@@ -394,6 +414,8 @@ export class PublicAnalyticsSdkService {
394
414
  trackPaymentInfoSubmitted(input) {
395
415
  return this.track({
396
416
  eventType: 'add_payment_info',
417
+ userId: input.userId,
418
+ environment: input.environment,
397
419
  eventId: input.eventId,
398
420
  occurredAt: input.occurredAt,
399
421
  stepId: input.stepId,
@@ -406,6 +428,8 @@ export class PublicAnalyticsSdkService {
406
428
  trackCheckoutCompleted(input) {
407
429
  return this.track({
408
430
  eventType: 'checkout_completed',
431
+ userId: input.userId,
432
+ environment: input.environment,
409
433
  eventId: input.eventId,
410
434
  occurredAt: input.occurredAt,
411
435
  stepId: input.stepId,
@@ -418,6 +442,8 @@ export class PublicAnalyticsSdkService {
418
442
  trackPaymentCheckoutSucceeded(input) {
419
443
  return this.track({
420
444
  eventType: 'payment_checkout_succeeded',
445
+ userId: input.userId,
446
+ environment: input.environment,
421
447
  eventId: input.eventId,
422
448
  occurredAt: input.occurredAt,
423
449
  stepId: input.stepId,
@@ -430,6 +456,8 @@ export class PublicAnalyticsSdkService {
430
456
  trackPaymentCheckoutReturned(input) {
431
457
  return this.track({
432
458
  eventType: 'payment_checkout_returned',
459
+ userId: input.userId,
460
+ environment: input.environment,
433
461
  eventId: input.eventId,
434
462
  occurredAt: input.occurredAt,
435
463
  stepId: input.stepId,
@@ -518,13 +546,14 @@ export class PublicAnalyticsSdkService {
518
546
  const analyticsEnvironment = resolveAnalyticsEnvironment();
519
547
  const batch = events.map((event) => {
520
548
  var _a, _b;
521
- return ({
549
+ const eventEnvironment = event.environment || analyticsEnvironment;
550
+ return {
522
551
  event: toPostHogEventName(event.eventType),
523
- properties: buildDefinedRecord(Object.assign(Object.assign({ distinct_id: this.ensureUserId(), $groups: {
552
+ properties: buildDefinedRecord(Object.assign(Object.assign({ distinct_id: event.userId || this.ensureUserId(), $groups: {
524
553
  project: PROJECT_ID,
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 })),
554
+ }, $insert_id: event.eventId, project_id: PROJECT_ID, funnel_id: FUNNEL_ID || undefined, funnel_version_id: FUNNEL_VERSION_ID || undefined, environment: eventEnvironment, test: eventEnvironment === '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 })),
526
555
  timestamp: event.occurredAt,
527
- });
556
+ };
528
557
  });
529
558
  const payload = JSON.stringify({
530
559
  api_key: POSTHOG_PROJECT_API_KEY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/analytics",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "test:run": "vitest run --passWithNoTests"
32
32
  },
33
33
  "dependencies": {
34
- "@funnelsgrove/runtime": "0.1.16"
34
+ "@funnelsgrove/runtime": "0.1.42"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^20",