@funnelsgrove/analytics 0.1.8 → 0.1.10

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,4 +1,4 @@
1
- type GoogleTagEventName = 'purchase';
1
+ type GoogleTagEventName = 'begin_checkout' | 'purchase';
2
2
  export type GoogleTagHeadScript = {
3
3
  id: string;
4
4
  src?: string;
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { GOOGLE_ANALYTICS_ID, GOOGLE_TAG_ENABLED, GOOGLE_TAG_EVENT_TARGET, GOOGLE_TAG_MANAGER_ID, } from './runtime-api.config.js';
2
13
  import { buildBrowserPurchaseAnalyticsAttributes } from './purchase-attributes.service.js';
3
14
  const normalizeEventTarget = (value) => {
@@ -109,14 +120,35 @@ export const buildGoogleTagHeadScripts = () => {
109
120
  : []),
110
121
  ];
111
122
  };
123
+ const toGoogleTagString = (value) => {
124
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
125
+ };
126
+ const toGoogleTagNumber = (value) => {
127
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
128
+ };
129
+ const buildGoogleTagItem = (parameters) => {
130
+ const itemId = toGoogleTagString(parameters.provider_plan_id) || toGoogleTagString(parameters.plan_id);
131
+ if (!itemId) {
132
+ return undefined;
133
+ }
134
+ return {
135
+ item_id: itemId,
136
+ item_name: toGoogleTagString(parameters.plan_id) || itemId,
137
+ price: toGoogleTagNumber(parameters.value),
138
+ quantity: 1,
139
+ };
140
+ };
112
141
  export const mapAnalyticsEventToGoogleTagEvent = (event) => {
113
142
  var _a;
114
143
  switch (event.eventType) {
115
- case 'checkout_completed':
144
+ case 'checkout_started': {
145
+ const _b = buildBrowserPurchaseAnalyticsAttributes((_a = event.metadata) !== null && _a !== void 0 ? _a : {}), { transaction_id: _transactionId } = _b, baseParameters = __rest(_b, ["transaction_id"]);
146
+ const item = buildGoogleTagItem(baseParameters);
116
147
  return {
117
- eventName: 'purchase',
118
- parameters: sanitizeGoogleTagParameters(buildBrowserPurchaseAnalyticsAttributes(Object.assign(Object.assign({}, ((_a = event.metadata) !== null && _a !== void 0 ? _a : {})), { transactionId: event.eventId }))),
148
+ eventName: 'begin_checkout',
149
+ parameters: sanitizeGoogleTagParameters(Object.assign(Object.assign({}, baseParameters), (item ? { items: [item] } : {}))),
119
150
  };
151
+ }
120
152
  default:
121
153
  return null;
122
154
  }
@@ -11,15 +11,24 @@ export type AnalyticsEventForMetaPixel = {
11
11
  };
12
12
  declare global {
13
13
  interface Window {
14
- fbq?: (...args: unknown[]) => void;
14
+ fbq?: MetaPixelQueue;
15
+ _fbq?: MetaPixelQueue;
15
16
  }
16
17
  }
18
+ type MetaPixelQueue = ((...args: unknown[]) => void) & {
19
+ callMethod?: (...args: unknown[]) => void;
20
+ loaded?: boolean;
21
+ push?: MetaPixelQueue;
22
+ queue?: unknown[][];
23
+ version?: string;
24
+ };
17
25
  export declare const mapAnalyticsEventToMetaPixelEvent: (event: AnalyticsEventForMetaPixel) => MetaPixelTrackInput | null;
18
26
  export declare class MetaPixelService {
19
27
  private initialized;
20
28
  track(input: MetaPixelTrackInput): void;
21
29
  private isConfigured;
22
30
  private ensureInitialized;
31
+ private installQueue;
23
32
  private installScript;
24
33
  }
25
34
  export declare const metaPixelService: MetaPixelService;
@@ -73,19 +73,43 @@ export class MetaPixelService {
73
73
  return Boolean(META_PIXEL_ENABLED && META_PIXEL_ID && typeof window !== 'undefined');
74
74
  }
75
75
  ensureInitialized() {
76
- var _a, _b;
77
76
  if (this.initialized) {
78
77
  return;
79
78
  }
80
79
  this.initialized = true;
80
+ this.installQueue();
81
81
  this.installScript();
82
- (_a = window.fbq) === null || _a === void 0 ? void 0 : _a.call(window, 'init', META_PIXEL_ID);
83
- (_b = window.fbq) === null || _b === void 0 ? void 0 : _b.call(window, 'track', 'PageView');
82
+ const fbq = window.fbq;
83
+ fbq === null || fbq === void 0 ? void 0 : fbq('init', META_PIXEL_ID);
84
+ fbq === null || fbq === void 0 ? void 0 : fbq('track', 'PageView');
85
+ }
86
+ installQueue() {
87
+ if (window.fbq) {
88
+ return;
89
+ }
90
+ const fbq = ((...args) => {
91
+ var _a;
92
+ if (fbq.callMethod) {
93
+ fbq.callMethod(...args);
94
+ return;
95
+ }
96
+ (_a = fbq.queue) === null || _a === void 0 ? void 0 : _a.push(args);
97
+ });
98
+ window._fbq = window._fbq || fbq;
99
+ fbq.push = fbq;
100
+ fbq.loaded = true;
101
+ fbq.version = '2.0';
102
+ fbq.queue = [];
103
+ window.fbq = fbq;
84
104
  }
85
105
  installScript() {
106
+ var _a;
86
107
  if (typeof document === 'undefined') {
87
108
  return;
88
109
  }
110
+ if ((_a = document.querySelector) === null || _a === void 0 ? void 0 : _a.call(document, 'script[src="https://connect.facebook.net/en_US/fbevents.js"]')) {
111
+ return;
112
+ }
89
113
  const firstScript = document.getElementsByTagName('script')[0];
90
114
  const parent = firstScript === null || firstScript === void 0 ? void 0 : firstScript.parentNode;
91
115
  if (!parent) {
@@ -2,11 +2,61 @@ import { buildMainApiUrl, buildSdkHeaders, FUNNEL_ID, FUNNEL_VERSION_ID, getFunn
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';
5
+ import { currentBrowserPurchaseUrl, sanitizePurchaseUrl, } from './purchase-attributes.service.js';
5
6
  const DEFAULT_OPTIONS = {
6
7
  batchSize: 20,
7
8
  flushIntervalMs: 1500,
8
9
  };
9
10
  const POSTHOG_BATCH_ENDPOINT = '/batch/';
11
+ const DEFAULT_FUNNEL_DOMAIN_SIGNAL = 'funnelsgrove';
12
+ const normalizeEnvironment = (value) => {
13
+ if (typeof value !== 'string') {
14
+ return null;
15
+ }
16
+ const normalized = value.trim().toLowerCase();
17
+ if (normalized === 'test') {
18
+ return 'test';
19
+ }
20
+ if (normalized === 'live' || normalized === 'prod' || normalized === 'production') {
21
+ return 'live';
22
+ }
23
+ return null;
24
+ };
25
+ const readCookieValue = (name) => {
26
+ var _a, _b;
27
+ if (!canUseDom() || typeof document === 'undefined') {
28
+ return null;
29
+ }
30
+ return (((_b = (_a = document.cookie) === null || _a === void 0 ? void 0 : _a.split(';').map((part) => part.trim()).find((part) => part.startsWith(`${name}=`))) === null || _b === void 0 ? void 0 : _b.slice(name.length + 1)) || null);
31
+ };
32
+ const resolveAnalyticsEnvironment = () => {
33
+ var _a, _b, _c, _d;
34
+ if (!canUseDom()) {
35
+ return 'live';
36
+ }
37
+ try {
38
+ const queryMode = normalizeEnvironment(new URLSearchParams(((_a = window.location) === null || _a === void 0 ? void 0 : _a.search) || '').get('mode'));
39
+ if (queryMode) {
40
+ return queryMode;
41
+ }
42
+ const cookieMode = normalizeEnvironment(readCookieValue('funnel-mode'));
43
+ if (cookieMode) {
44
+ return cookieMode;
45
+ }
46
+ const hostname = ((_c = (_b = window.location) === null || _b === void 0 ? void 0 : _b.hostname) === null || _c === void 0 ? void 0 : _c.trim().toLowerCase()) || '';
47
+ if (hostname.includes(DEFAULT_FUNNEL_DOMAIN_SIGNAL)) {
48
+ return 'test';
49
+ }
50
+ const storageMode = normalizeEnvironment((_d = window.localStorage) === null || _d === void 0 ? void 0 : _d.getItem('funnel-mode'));
51
+ if (storageMode) {
52
+ return storageMode;
53
+ }
54
+ }
55
+ catch (_e) {
56
+ return 'live';
57
+ }
58
+ return 'live';
59
+ };
10
60
  const asRecord = (value) => {
11
61
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
12
62
  return {};
@@ -79,6 +129,13 @@ const normalizeFeatureFlags = (featureFlags) => {
79
129
  const buildFeatureFlagProperties = (featureFlags) => {
80
130
  return Object.fromEntries(Object.entries(featureFlags).map(([key, value]) => [`$feature/${key}`, value]));
81
131
  };
132
+ const buildEventMetadata = (eventType, metadata) => {
133
+ if (eventType !== 'checkout_completed') {
134
+ return metadata;
135
+ }
136
+ const checkoutUrl = sanitizePurchaseUrl(metadata.url) || currentBrowserPurchaseUrl();
137
+ return checkoutUrl ? Object.assign(Object.assign({}, metadata), { url: checkoutUrl }) : metadata;
138
+ };
82
139
  export class PublicAnalyticsSdkService {
83
140
  constructor(options = {}) {
84
141
  this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
@@ -112,7 +169,7 @@ export class PublicAnalyticsSdkService {
112
169
  user_id: userId,
113
170
  email: asString(input.email) || undefined,
114
171
  fullName: asString(input.fullName) || undefined,
115
- metadata: asRecord(input.metadata),
172
+ metadata: Object.assign({ environment: resolveAnalyticsEnvironment() }, asRecord(input.metadata)),
116
173
  }),
117
174
  });
118
175
  if (!response.ok) {
@@ -170,10 +227,11 @@ export class PublicAnalyticsSdkService {
170
227
  return null;
171
228
  }
172
229
  const eventId = asString(event.eventId) || buildEventId();
230
+ const metadata = buildEventMetadata(eventType, asRecord(event.metadata));
173
231
  const metaPixelEvent = mapAnalyticsEventToMetaPixelEvent({
174
232
  eventType,
175
233
  eventId,
176
- metadata: asRecord(event.metadata),
234
+ metadata,
177
235
  });
178
236
  if (metaPixelEvent) {
179
237
  metaPixelService.track(metaPixelEvent);
@@ -181,7 +239,7 @@ export class PublicAnalyticsSdkService {
181
239
  const googleTagEvent = mapAnalyticsEventToGoogleTagEvent({
182
240
  eventType,
183
241
  eventId,
184
- metadata: asRecord(event.metadata),
242
+ metadata,
185
243
  });
186
244
  if (googleTagEvent) {
187
245
  googleTagService.track(googleTagEvent);
@@ -202,7 +260,7 @@ export class PublicAnalyticsSdkService {
202
260
  selected: asRecord(event.selected),
203
261
  payload: asRecord(event.payload),
204
262
  context: asRecord(event.context),
205
- metadata: asRecord(event.metadata),
263
+ metadata,
206
264
  featureFlags: normalizeFeatureFlags(event.featureFlags),
207
265
  };
208
266
  this.eventQueue.push(envelope);
@@ -393,7 +451,7 @@ export class PublicAnalyticsSdkService {
393
451
  event: toPostHogEventName(event.eventType),
394
452
  properties: buildDefinedRecord(Object.assign(Object.assign({ distinct_id: this.ensureUserId(), $groups: {
395
453
  project: PROJECT_ID,
396
- }, $insert_id: event.eventId, project_id: PROJECT_ID, funnel_id: FUNNEL_ID || undefined, funnel_version_id: FUNNEL_VERSION_ID || undefined, step_id: event.stepId || undefined, step_name: event.stepName || 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 })),
454
+ }, $insert_id: event.eventId, project_id: PROJECT_ID, funnel_id: FUNNEL_ID || undefined, funnel_version_id: FUNNEL_VERSION_ID || undefined, environment: resolveAnalyticsEnvironment(), step_id: event.stepId || undefined, step_name: event.stepName || 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 })),
397
455
  timestamp: event.occurredAt,
398
456
  });
399
457
  });
@@ -1,16 +1,26 @@
1
1
  export type PurchaseAnalyticsAttributesInput = {
2
2
  amountCents?: unknown;
3
3
  attribution?: unknown;
4
+ checkoutSessionId?: unknown;
5
+ checkout_session_id?: unknown;
4
6
  couponId?: unknown;
5
7
  currency?: unknown;
6
8
  environment?: unknown;
9
+ fallbackTransactionId?: unknown;
10
+ fallback_transaction_id?: unknown;
7
11
  funnelId?: unknown;
8
12
  funnelUserDocument?: unknown;
9
13
  funnelVersion?: unknown;
10
14
  funnelVersionId?: unknown;
15
+ gaClientId?: unknown;
16
+ ga_client_id?: unknown;
11
17
  geoCity?: unknown;
12
18
  geoCountry?: unknown;
19
+ googleAnalyticsClientId?: unknown;
20
+ google_analytics_client_id?: unknown;
13
21
  ipAddress?: unknown;
22
+ paymentIntentId?: unknown;
23
+ payment_intent_id?: unknown;
14
24
  planId?: unknown;
15
25
  projectId?: unknown;
16
26
  providerPlanId?: unknown;
@@ -21,6 +31,9 @@ export type PurchaseAnalyticsAttributesInput = {
21
31
  userId?: unknown;
22
32
  value?: unknown;
23
33
  };
34
+ export declare const sanitizePurchaseUrl: (value: unknown) => string | undefined;
35
+ export declare const currentBrowserPurchaseUrl: () => string | undefined;
36
+ export declare const currentGoogleAnalyticsClientId: () => string | undefined;
24
37
  export declare const buildPurchaseAnalyticsAttributes: (input?: PurchaseAnalyticsAttributesInput & Record<string, unknown>, options?: {
25
38
  includeUrl?: boolean;
26
39
  }) => Record<string, unknown>;
@@ -1,5 +1,32 @@
1
1
  const STRIPE_METADATA_KEY_MAX_LENGTH = 40;
2
2
  const STRIPE_METADATA_VALUE_MAX_LENGTH = 500;
3
+ const SENSITIVE_PURCHASE_URL_QUERY_KEYS = new Set([
4
+ 'customeremail',
5
+ 'customer_email',
6
+ 'email',
7
+ 'fullname',
8
+ 'full_name',
9
+ 'name',
10
+ 'phone',
11
+ 'phonenumber',
12
+ 'phone_number',
13
+ ]);
14
+ const FLAT_ATTRIBUTION_KEYS = new Set([
15
+ '_fbc',
16
+ '_fbp',
17
+ 'epik',
18
+ 'fbc',
19
+ 'fbclid',
20
+ 'fbp',
21
+ 'gbraid',
22
+ 'gclid',
23
+ 'li_fat_id',
24
+ 'msclkid',
25
+ 'scclid',
26
+ 'ttclid',
27
+ 'twclid',
28
+ 'wbraid',
29
+ ]);
3
30
  const isRecord = (value) => {
4
31
  return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
5
32
  };
@@ -59,12 +86,74 @@ const normalizeAttributionTouch = (value) => {
59
86
  return [[normalizedKey, normalizedValue]];
60
87
  }));
61
88
  };
62
- const currentBrowserUrl = () => {
89
+ const isFlatAttributionKey = (key) => {
90
+ const normalizedKey = key.trim().toLowerCase();
91
+ return normalizedKey.startsWith('utm_') || FLAT_ATTRIBUTION_KEYS.has(normalizedKey);
92
+ };
93
+ const normalizeFlatAttributionTouch = (value) => {
94
+ return Object.fromEntries(Object.entries(value).flatMap(([key, candidate]) => {
95
+ const normalizedKey = key.trim();
96
+ if (!normalizedKey || !isFlatAttributionKey(normalizedKey)) {
97
+ return [];
98
+ }
99
+ const normalizedValue = toScalar(candidate);
100
+ return normalizedValue === undefined ? [] : [[normalizedKey, normalizedValue]];
101
+ }));
102
+ };
103
+ export const sanitizePurchaseUrl = (value) => {
104
+ const normalized = toString(value);
105
+ if (!normalized) {
106
+ return undefined;
107
+ }
108
+ try {
109
+ const parsed = new URL(normalized, typeof window !== 'undefined' ? window.location.origin : 'https://example.invalid');
110
+ for (const key of Array.from(parsed.searchParams.keys())) {
111
+ if (SENSITIVE_PURCHASE_URL_QUERY_KEYS.has(key.trim().toLowerCase())) {
112
+ parsed.searchParams.delete(key);
113
+ }
114
+ }
115
+ return parsed.toString();
116
+ }
117
+ catch (_a) {
118
+ return normalized;
119
+ }
120
+ };
121
+ export const currentBrowserPurchaseUrl = () => {
63
122
  var _a;
64
123
  if (typeof window === 'undefined') {
65
124
  return undefined;
66
125
  }
67
- return toString((_a = window.location) === null || _a === void 0 ? void 0 : _a.href);
126
+ return sanitizePurchaseUrl((_a = window.location) === null || _a === void 0 ? void 0 : _a.href);
127
+ };
128
+ const readBrowserCookie = (name) => {
129
+ if (typeof document === 'undefined') {
130
+ return undefined;
131
+ }
132
+ const prefix = `${name}=`;
133
+ const cookie = document.cookie
134
+ .split(';')
135
+ .map((value) => value.trim())
136
+ .find((value) => value.startsWith(prefix));
137
+ if (!cookie) {
138
+ return undefined;
139
+ }
140
+ try {
141
+ return decodeURIComponent(cookie.slice(prefix.length));
142
+ }
143
+ catch (_a) {
144
+ return cookie.slice(prefix.length);
145
+ }
146
+ };
147
+ export const currentGoogleAnalyticsClientId = () => {
148
+ const gaCookie = readBrowserCookie('_ga');
149
+ if (!gaCookie) {
150
+ return undefined;
151
+ }
152
+ const parts = gaCookie.split('.');
153
+ if (parts.length >= 4 && /^GA\d+$/.test(parts[0])) {
154
+ return parts.slice(-2).join('.');
155
+ }
156
+ return gaCookie.trim() || undefined;
68
157
  };
69
158
  export const buildPurchaseAnalyticsAttributes = (input = {}, options = {}) => {
70
159
  var _a, _b;
@@ -75,7 +164,9 @@ export const buildPurchaseAnalyticsAttributes = (input = {}, options = {}) => {
75
164
  const transactionInfo = asRecord(document.transactionInfo);
76
165
  const amountCents = toNumber(input.amountCents);
77
166
  const value = (_b = toNumber(input.value)) !== null && _b !== void 0 ? _b : (amountCents === undefined ? undefined : amountCents / 100);
78
- return buildDefinedRecord(Object.assign(Object.assign({}, normalizeAttributionTouch(attribution.firstTouch)), { currency: toCurrency(input.currency), value, plan_id: firstString(input.planId, input.plan_id), provider_plan_id: firstString(input.providerPlanId, input.provider_plan_id), coupon_id: firstString(input.couponId, input.coupon_id), environment: firstString(input.environment), user_id: firstString(input.userId, input.user_id), project_id: firstString(input.projectId, input.project_id), funnel_id: firstString(input.funnelId, input.funnel_id), funnel_version: firstString(input.funnelVersion, input.funnelVersionId, input.funnel_version), ip_address: firstString(input.ipAddress, input.ip_address, transactionInfo.ipAddress, transactionInfo.ip_address), user_agent: firstString(input.userAgent, input.user_agent, attributionContext.userAgent), timezone: firstString(input.timezone, input.time_zone, progressAttributes.timezone, progressAttributes.time_zone, document.timezone, document.time_zone, attributionContext.timezone, attributionContext.time_zone), geo_city: firstString(input.geoCity, input.geo_city, progressAttributes.geo_city, progressAttributes.geoCity, document.geo_city, document.geoCity, asRecord(document.geo).city, attributionContext.geo_city, attributionContext.geoCity, attributionContext.cityName, attributionContext.city), geo_country: firstString(input.geoCountry, input.geo_country, progressAttributes.geo_country, progressAttributes.geoCountry, document.geo_country, document.geoCountry, asRecord(document.geo).country, attributionContext.geo_country, attributionContext.geoCountry, attributionContext.countryName, attributionContext.countryCode, attributionContext.country), transaction_id: firstString(input.transactionId, input.transaction_id), url: options.includeUrl ? firstString(input.url, currentBrowserUrl()) : undefined }));
167
+ return buildDefinedRecord(Object.assign(Object.assign(Object.assign({}, normalizeFlatAttributionTouch(input)), normalizeAttributionTouch(attribution.firstTouch)), { currency: toCurrency(input.currency), value, plan_id: firstString(input.planId, input.plan_id), provider_plan_id: firstString(input.providerPlanId, input.provider_plan_id), coupon_id: firstString(input.couponId, input.coupon_id), environment: firstString(input.environment), user_id: firstString(input.userId, input.user_id), project_id: firstString(input.projectId, input.project_id), funnel_id: firstString(input.funnelId, input.funnel_id), funnel_version: firstString(input.funnelVersion, input.funnelVersionId, input.funnel_version), ip_address: firstString(input.ipAddress, input.ip_address, transactionInfo.ipAddress, transactionInfo.ip_address), user_agent: firstString(input.userAgent, input.user_agent, attributionContext.userAgent), timezone: firstString(input.timezone, input.time_zone, progressAttributes.timezone, progressAttributes.time_zone, document.timezone, document.time_zone, attributionContext.timezone, attributionContext.time_zone), geo_city: firstString(input.geoCity, input.geo_city, progressAttributes.geo_city, progressAttributes.geoCity, document.geo_city, document.geoCity, asRecord(document.geo).city, attributionContext.geo_city, attributionContext.geoCity, attributionContext.cityName, attributionContext.city), geo_country: firstString(input.geoCountry, input.geo_country, progressAttributes.geo_country, progressAttributes.geoCountry, document.geo_country, document.geoCountry, asRecord(document.geo).country, attributionContext.geo_country, attributionContext.geoCountry, attributionContext.countryName, attributionContext.countryCode, attributionContext.country), transaction_id: firstString(input.transactionId, input.transaction_id, input.checkoutSessionId, input.checkout_session_id, input.paymentIntentId, input.payment_intent_id, input.fallbackTransactionId, input.fallback_transaction_id), url: options.includeUrl
168
+ ? sanitizePurchaseUrl(firstString(input.url, currentBrowserPurchaseUrl()))
169
+ : undefined }));
79
170
  };
80
171
  export const buildBrowserPurchaseAnalyticsAttributes = (input = {}) => {
81
172
  return buildPurchaseAnalyticsAttributes(input, { includeUrl: true });
@@ -98,5 +189,5 @@ export const toStripeMetadata = (attributes) => {
98
189
  }));
99
190
  };
100
191
  export const buildStripePurchaseMetadata = (input = {}) => {
101
- return toStripeMetadata(buildPurchaseAnalyticsAttributes(input, { includeUrl: false }));
192
+ return toStripeMetadata(Object.assign(Object.assign({}, buildPurchaseAnalyticsAttributes(input, { includeUrl: false })), { ga_client_id: firstString(input.gaClientId, input.ga_client_id, input.googleAnalyticsClientId, input.google_analytics_client_id, currentGoogleAnalyticsClientId()) }));
102
193
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/analytics",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",