@funnelsgrove/analytics 0.1.31 → 0.1.33

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.
package/README.md CHANGED
@@ -52,13 +52,14 @@ full `send_to` destination, such as `AW-123456789/ConversionLabel`.
52
52
 
53
53
  - `NEXT_PUBLIC_GOOGLE_TAG_LEAD_SEND_TO` sends an Ads `conversion` event when the
54
54
  SDK records a lead/email capture.
55
+ - `NEXT_PUBLIC_GOOGLE_TAG_LEAD_VALUE` sets the numeric value for the lead Ads
56
+ conversion. Empty or invalid values default to `0`.
55
57
  - `NEXT_PUBLIC_GOOGLE_TAG_PURCHASE_SEND_TO` sends an Ads `conversion` event when
56
58
  the SDK records a paid checkout completion.
57
59
 
58
- When either `send_to` value is present, Google Tag is treated as enabled even if
59
- `NEXT_PUBLIC_GOOGLE_TAG_ENABLED` is not set. The `AW-...` prefix is used to load
60
- and configure `gtag.js`; the full `AW-.../...` value is sent on the conversion
61
- event.
60
+ Ads conversion values only fire when `NEXT_PUBLIC_GOOGLE_TAG_ENABLED=true`.
61
+ The `AW-...` prefix is used to load and configure `gtag.js`; the full
62
+ `AW-.../...` value is sent on the conversion event.
62
63
 
63
64
  ## Build, Test, Publish
64
65
 
@@ -1,8 +1,5 @@
1
- import { GOOGLE_TAG_CONFIG_IDS, GOOGLE_TAG_ENABLED, GOOGLE_TAG_EVENT_TARGET, GOOGLE_TAG_LEAD_SEND_TO, GOOGLE_TAG_MANAGER_ID, GOOGLE_TAG_PURCHASE_SEND_TO, GOOGLE_TAG_SCRIPT_ID, } from './runtime-api.config.js';
1
+ import { GOOGLE_TAG_CONFIG_IDS, GOOGLE_TAG_ENABLED, GOOGLE_TAG_LEAD_VALUE, GOOGLE_TAG_LEAD_SEND_TO, GOOGLE_TAG_MANAGER_ID, GOOGLE_TAG_PURCHASE_SEND_TO, GOOGLE_TAG_SCRIPT_ID, } from './runtime-api.config.js';
2
2
  import { buildBrowserPurchaseAnalyticsAttributes, buildPurchaseAnalyticsAttributes, currentBrowserPurchaseUrl, } from './purchase-attributes.service.js';
3
- const normalizeEventTarget = (value) => {
4
- return value === 'dataLayer' || value === 'gtag' || value === 'both' ? value : 'both';
5
- };
6
3
  const SENSITIVE_GOOGLE_TAG_PARAMETER_KEYS = new Set([
7
4
  'customerEmail',
8
5
  'customer_email',
@@ -68,6 +65,10 @@ const firstString = (...values) => {
68
65
  }
69
66
  return undefined;
70
67
  };
68
+ const parseGoogleTagNumber = (value, fallback) => {
69
+ const parsed = Number(value.trim());
70
+ return Number.isFinite(parsed) ? parsed : fallback;
71
+ };
71
72
  const buildDefinedRecord = (value) => {
72
73
  return Object.fromEntries(Object.entries(value).filter(([, candidate]) => candidate !== undefined && candidate !== null && candidate !== ''));
73
74
  };
@@ -219,7 +220,7 @@ export const mapAnalyticsEventToGoogleAdsConversionEvent = (event) => {
219
220
  }
220
221
  return {
221
222
  eventName: 'conversion',
222
- parameters: buildGoogleAdsConversionParameters(Object.assign(Object.assign({}, buildStepParameters(event, { includeEventId: true })), { value: 0, currency: 'USD' }), GOOGLE_TAG_LEAD_SEND_TO),
223
+ parameters: buildGoogleAdsConversionParameters(Object.assign(Object.assign({}, buildStepParameters(event, { includeEventId: true })), { value: parseGoogleTagNumber(GOOGLE_TAG_LEAD_VALUE, 0), currency: 'USD' }), GOOGLE_TAG_LEAD_SEND_TO),
223
224
  };
224
225
  case 'checkout_completed':
225
226
  if (!GOOGLE_TAG_PURCHASE_SEND_TO) {
@@ -258,13 +259,8 @@ export class GoogleTagService {
258
259
  }
259
260
  this.initialize();
260
261
  const parameters = sanitizeGoogleTagParameters((_a = input.parameters) !== null && _a !== void 0 ? _a : {});
261
- const eventTarget = normalizeEventTarget(GOOGLE_TAG_EVENT_TARGET);
262
- if (eventTarget === 'dataLayer' || eventTarget === 'both') {
263
- (_b = window.dataLayer) === null || _b === void 0 ? void 0 : _b.push(Object.assign({ event: input.eventName }, parameters));
264
- }
265
- if (eventTarget === 'gtag' || eventTarget === 'both') {
266
- (_c = window.gtag) === null || _c === void 0 ? void 0 : _c.call(window, 'event', input.eventName, parameters);
267
- }
262
+ (_b = window.dataLayer) === null || _b === void 0 ? void 0 : _b.push(Object.assign({ event: input.eventName }, parameters));
263
+ (_c = window.gtag) === null || _c === void 0 ? void 0 : _c.call(window, 'event', input.eventName, parameters);
268
264
  }
269
265
  isConfigured() {
270
266
  return Boolean(GOOGLE_TAG_ENABLED &&
@@ -14,6 +14,14 @@ export type PurchaseAnalyticsAttributesInput = {
14
14
  planId?: unknown;
15
15
  projectId?: unknown;
16
16
  providerPlanId?: unknown;
17
+ checkoutStartSource?: unknown;
18
+ checkout_start_source?: unknown;
19
+ stepId?: unknown;
20
+ step_id?: unknown;
21
+ stepName?: unknown;
22
+ step_name?: unknown;
23
+ stepType?: unknown;
24
+ step_type?: unknown;
17
25
  transactionId?: unknown;
18
26
  timezone?: unknown;
19
27
  url?: unknown;
@@ -135,7 +135,7 @@ export const buildPurchaseAnalyticsAttributes = (input = {}, options = {}) => {
135
135
  const amountCents = toNumber(input.amountCents);
136
136
  const value = (_b = toNumber(input.value)) !== null && _b !== void 0 ? _b : (amountCents === undefined ? undefined : amountCents / 100);
137
137
  const funnelUserId = firstString(input.userId, input.user_id, input.cwClientUserId, input.cw_client_user_id);
138
- 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: funnelUserId, cw_client_user_id: funnelUserId, 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
138
+ 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), checkout_start_source: firstString(input.checkoutStartSource, input.checkout_start_source), step_id: firstString(input.stepId, input.step_id), step_name: firstString(input.stepName, input.step_name), step_type: firstString(input.stepType, input.step_type), user_id: funnelUserId, cw_client_user_id: funnelUserId, 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
139
139
  ? sanitizePurchaseUrl(firstString(input.url, currentBrowserPurchaseUrl()))
140
140
  : undefined }));
141
141
  };
@@ -11,6 +11,7 @@ export declare const GOOGLE_ANALYTICS_ID: string;
11
11
  export declare const GOOGLE_TAG_MANAGER_ID: string;
12
12
  export declare const GOOGLE_TAG_EVENT_TARGET: string;
13
13
  export declare const GOOGLE_TAG_LEAD_SEND_TO: string;
14
+ export declare const GOOGLE_TAG_LEAD_VALUE: string;
14
15
  export declare const GOOGLE_TAG_PURCHASE_SEND_TO: string;
15
16
  export declare const GOOGLE_ADS_CONVERSION_ID: string;
16
17
  export declare const GOOGLE_TAG_CONFIG_IDS: string[];
@@ -45,6 +45,7 @@ export const GOOGLE_ANALYTICS_ID = trimEnv(runtimeEnvConfig.googleAnalyticsId);
45
45
  export const GOOGLE_TAG_MANAGER_ID = trimEnv(runtimeEnvConfig.googleTagManagerId);
46
46
  export const GOOGLE_TAG_EVENT_TARGET = trimEnv(runtimeEnvConfig.googleTagEventTarget);
47
47
  export const GOOGLE_TAG_LEAD_SEND_TO = trimEnv(runtimeEnvConfig.googleTagLeadSendTo);
48
+ export const GOOGLE_TAG_LEAD_VALUE = trimEnv(runtimeEnvConfig.googleTagLeadValue);
48
49
  export const GOOGLE_TAG_PURCHASE_SEND_TO = trimEnv(runtimeEnvConfig.googleTagPurchaseSendTo);
49
50
  export const GOOGLE_ADS_CONVERSION_ID = resolveGoogleAdsConversionId(GOOGLE_TAG_LEAD_SEND_TO, GOOGLE_TAG_PURCHASE_SEND_TO);
50
51
  export const GOOGLE_TAG_CONFIG_IDS = Array.from(new Set([
@@ -52,8 +53,7 @@ export const GOOGLE_TAG_CONFIG_IDS = Array.from(new Set([
52
53
  GOOGLE_ADS_CONVERSION_ID,
53
54
  ].filter(Boolean)));
54
55
  export const GOOGLE_TAG_SCRIPT_ID = (_j = GOOGLE_TAG_CONFIG_IDS[0]) !== null && _j !== void 0 ? _j : '';
55
- export const GOOGLE_TAG_ENABLED = (trimEnv(runtimeEnvConfig.googleTagEnabled) === 'true' ||
56
- Boolean(GOOGLE_TAG_LEAD_SEND_TO || GOOGLE_TAG_PURCHASE_SEND_TO));
56
+ export const GOOGLE_TAG_ENABLED = trimEnv(runtimeEnvConfig.googleTagEnabled) === 'true';
57
57
  export const STRIPE_ACTIVE_MODE = ((_k = runtimeEnvConfig.stripeActiveMode) !== null && _k !== void 0 ? _k : '').trim().toLowerCase();
58
58
  export const hasRealFunnelSdkPublishableKey = (value = FUNNEL_SDK_PUBLISHABLE_KEY) => {
59
59
  const normalized = value.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/analytics",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
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.51"
34
+ "@funnelsgrove/runtime": "0.1.52"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^20",