@funnelsgrove/analytics 0.1.88 → 0.1.90

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.
@@ -2,6 +2,7 @@ type MetaPixelEventName = 'AddPaymentInfo' | 'InitiateCheckout' | 'Lead' | 'View
2
2
  export type MetaPixelTrackInput = {
3
3
  eventName: MetaPixelEventName;
4
4
  eventId: string;
5
+ environment?: 'test' | 'live';
5
6
  customData?: Record<string, unknown>;
6
7
  };
7
8
  export type AnalyticsEventForMetaPixel = {
@@ -1,4 +1,5 @@
1
- import { META_PIXEL_ENABLED, META_PIXEL_ID } from './runtime-api.config.js';
1
+ import { isSystemPreviewHostname } from '@funnelsgrove/runtime';
2
+ import { META_PIXEL_ENABLED, META_PIXEL_ID, STRIPE_ACTIVE_MODE } from './runtime-api.config.js';
2
3
  const toNumber = (value) => {
3
4
  if (typeof value !== 'number' || !Number.isFinite(value)) {
4
5
  return null;
@@ -22,6 +23,27 @@ const buildCommerceCustomData = (metadata = {}) => {
22
23
  }
23
24
  return customData;
24
25
  };
26
+ const isNonLiveRuntime = () => {
27
+ var _a, _b, _c, _d, _e, _f, _g, _h;
28
+ if (STRIPE_ACTIVE_MODE === 'test') {
29
+ return true;
30
+ }
31
+ try {
32
+ const params = new URLSearchParams(((_a = window.location) === null || _a === void 0 ? void 0 : _a.search) || '');
33
+ const hostname = ((_c = (_b = window.location) === null || _b === void 0 ? void 0 : _b.hostname) === null || _c === void 0 ? void 0 : _c.toLowerCase().replace(/\.+$/, '')) || '';
34
+ const cookieMode = typeof document === 'undefined' ? undefined : (_e = (_d = document.cookie) === null || _d === void 0 ? void 0 : _d.split(';').map((part) => part.trim()).find((part) => part.startsWith('funnel-mode='))) === null || _e === void 0 ? void 0 : _e.slice('funnel-mode='.length);
35
+ return params.get('previewFrame') === '1'
36
+ || ((_f = params.get('mode')) === null || _f === void 0 ? void 0 : _f.trim().toLowerCase()) === 'test'
37
+ || (cookieMode === null || cookieMode === void 0 ? void 0 : cookieMode.trim().toLowerCase()) === 'test'
38
+ || ((_h = (_g = window.localStorage) === null || _g === void 0 ? void 0 : _g.getItem('funnel-mode')) === null || _h === void 0 ? void 0 : _h.trim().toLowerCase()) === 'test'
39
+ || isSystemPreviewHostname(hostname)
40
+ || hostname === 'preview.funnelsgrove.dev'
41
+ || hostname.endsWith('.preview.funnelsgrove.dev');
42
+ }
43
+ catch (_j) {
44
+ return true;
45
+ }
46
+ };
25
47
  export const mapAnalyticsEventToMetaPixelEvent = (event) => {
26
48
  switch (event.eventType) {
27
49
  case 'first_step_viewed':
@@ -61,7 +83,7 @@ export class MetaPixelService {
61
83
  }
62
84
  track(input) {
63
85
  var _a, _b;
64
- if (!this.isConfigured()) {
86
+ if (input.environment === 'test' || !this.isConfigured() || isNonLiveRuntime()) {
65
87
  return;
66
88
  }
67
89
  this.ensureInitialized();
@@ -308,9 +308,9 @@ export class PublicAnalyticsSdkService {
308
308
  if (!eventId) {
309
309
  return;
310
310
  }
311
- this.trackBrowserDestinations('email_captured', eventId, buildDefinedRecord(Object.assign(Object.assign({}, asRecord(input.metadata)), { stepId: asString(input.stepId) || undefined, stepName: asString(input.stepName) || undefined, stepType: asString(input.stepType) || undefined })));
311
+ this.trackBrowserDestinations('email_captured', eventId, buildDefinedRecord(Object.assign(Object.assign({}, asRecord(input.metadata)), { stepId: asString(input.stepId) || undefined, stepName: asString(input.stepName) || undefined, stepType: asString(input.stepType) || undefined })), input.environment);
312
312
  }
313
- trackBrowserDestinations(eventType, eventId, metadata) {
313
+ trackBrowserDestinations(eventType, eventId, metadata, environment) {
314
314
  const metaPixelEvent = mapAnalyticsEventToMetaPixelEvent({
315
315
  eventType,
316
316
  eventId,
@@ -318,7 +318,7 @@ export class PublicAnalyticsSdkService {
318
318
  });
319
319
  if (metaPixelEvent) {
320
320
  try {
321
- metaPixelService.track(metaPixelEvent);
321
+ metaPixelService.track(Object.assign(Object.assign({}, metaPixelEvent), { environment }));
322
322
  }
323
323
  catch (_a) {
324
324
  // Browser destinations are best effort and independent.
@@ -347,7 +347,7 @@ export class PublicAnalyticsSdkService {
347
347
  const eventId = asString(event.eventId) || buildEventId();
348
348
  const metadata = buildEventMetadata(eventType, asRecord(event.metadata));
349
349
  const providerMetadata = buildDefinedRecord(Object.assign(Object.assign({}, metadata), { stepId: asString(event.stepId) || metadata.stepId, stepName: asString(event.stepName) || metadata.stepName, stepType: asString(event.stepType) || metadata.stepType }));
350
- this.trackBrowserDestinations(eventType, eventId, providerMetadata);
350
+ this.trackBrowserDestinations(eventType, eventId, providerMetadata, event.environment);
351
351
  if (!getFunnelSdkPublishableKey()) {
352
352
  return eventId;
353
353
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/analytics",
3
- "version": "0.1.88",
3
+ "version": "0.1.90",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",
@@ -36,7 +36,7 @@
36
36
  "test:run": "vitest run --passWithNoTests"
37
37
  },
38
38
  "dependencies": {
39
- "@funnelsgrove/runtime": "0.11.4"
39
+ "@funnelsgrove/runtime": "0.11.5"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "^20",