@funnelsgrove/analytics 0.1.30 → 0.1.32
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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,
|
|
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:
|
|
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
|
-
|
|
262
|
-
|
|
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 &&
|
|
@@ -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 =
|
|
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.
|
|
3
|
+
"version": "0.1.32",
|
|
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.
|
|
34
|
+
"@funnelsgrove/runtime": "0.1.52"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^20",
|