@aranova/tracking-react 0.6.1 → 0.7.1
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 +26 -0
- package/dist/index.d.mts +77 -15
- package/dist/index.d.ts +77 -15
- package/dist/index.js +65 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,32 @@ createRoot(document.getElementById('root')!).render(
|
|
|
52
52
|
);
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
### Multiple gtag IDs
|
|
56
|
+
|
|
57
|
+
To install multiple Google Ads tags simultaneously (for example a production MCC and a test MCC for verifying conversion actions before they touch the live account), pass `gtagIds` instead of `gtagId`. Every entry fires `gtag('config', ...)` on every page — gtag natively supports multiple configured tags.
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
<TrackingProvider
|
|
61
|
+
gtagIds={{
|
|
62
|
+
production: 'AW-111111111', // real client account
|
|
63
|
+
test: 'AW-222222222', // test MCC for development
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<App />
|
|
67
|
+
</TrackingProvider>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The labels are arbitrary and surface in the Aranova dashboard's SDK versions table. You can also stamp events with a deployment environment so the dashboard can filter out test traffic:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
createTracking({
|
|
74
|
+
apiKey: import.meta.env.VITE_ARANOVA_TRACKING_API_KEY,
|
|
75
|
+
endpoint: import.meta.env.VITE_ARANOVA_TRACKING_ENDPOINT,
|
|
76
|
+
environment: import.meta.env.MODE, // 'production' | 'development'
|
|
77
|
+
triggers: { /* ... */ },
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
55
81
|
## Manual Events
|
|
56
82
|
|
|
57
83
|
Manual events must be registered under `triggers.manual` before `trackEvent()` accepts them.
|
package/dist/index.d.mts
CHANGED
|
@@ -11,20 +11,6 @@ import { z } from 'zod';
|
|
|
11
11
|
*/
|
|
12
12
|
declare function ConsentBanner(): react_jsx_runtime.JSX.Element | null;
|
|
13
13
|
|
|
14
|
-
interface GoogleAdsTrackingProps {
|
|
15
|
-
/**
|
|
16
|
-
* Google Ads tag id, for example `AW-123456789`.
|
|
17
|
-
*/
|
|
18
|
-
gtagId: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Client component that loads Google Ads gtag and restores stored consent.
|
|
22
|
-
*
|
|
23
|
-
* Render once near the application root when the client site runs paid Google
|
|
24
|
-
* Ads. The component renders nothing.
|
|
25
|
-
*/
|
|
26
|
-
declare function GoogleAdsTracking({ gtagId }: GoogleAdsTrackingProps): null;
|
|
27
|
-
|
|
28
14
|
/**
|
|
29
15
|
* Visitor consent state stored by the SDK.
|
|
30
16
|
*
|
|
@@ -62,6 +48,23 @@ interface TrackingParams {
|
|
|
62
48
|
* whether a site uses the Next, React, or script-tag integration.
|
|
63
49
|
*/
|
|
64
50
|
type TrackingInstallSurface = 'next' | 'react' | 'script';
|
|
51
|
+
/**
|
|
52
|
+
* Deployment environment label for event tagging.
|
|
53
|
+
*
|
|
54
|
+
* Used to stamp tracking events with the deployment context so the dashboard
|
|
55
|
+
* can distinguish production traffic from dev test traffic. The backend
|
|
56
|
+
* enforces this via a Postgres enum, so values are strictly one of
|
|
57
|
+
* `'production'` or `'development'`.
|
|
58
|
+
*/
|
|
59
|
+
type TrackingEnvironment = 'production' | 'development';
|
|
60
|
+
/**
|
|
61
|
+
* Labelled map of Google Ads tag IDs.
|
|
62
|
+
*
|
|
63
|
+
* ALL entries are loaded simultaneously via `gtag('config', ...)` — the keys
|
|
64
|
+
* are human-readable labels (e.g. `production`, `test`) and the values are
|
|
65
|
+
* Google Ads tag IDs (e.g. `AW-123456789`).
|
|
66
|
+
*/
|
|
67
|
+
type GtagEnvironmentMap = Record<string, string>;
|
|
65
68
|
/**
|
|
66
69
|
* Runtime context attached to tracking sessions and events.
|
|
67
70
|
*/
|
|
@@ -78,6 +81,16 @@ interface TrackingClientContext {
|
|
|
78
81
|
page_title: string | null;
|
|
79
82
|
/** Browser document referrer at client creation time. */
|
|
80
83
|
referrer: string | null;
|
|
84
|
+
/**
|
|
85
|
+
* Deployment environment label, e.g. `'production'`, `'development'`.
|
|
86
|
+
*
|
|
87
|
+
* Always set — defaults to `'production'` when the consumer doesn't
|
|
88
|
+
* pass `environment` to the factory. Sending `null` would fail the
|
|
89
|
+
* backend's strict enum validation.
|
|
90
|
+
*/
|
|
91
|
+
environment: TrackingEnvironment;
|
|
92
|
+
/** All active gtag IDs loaded on this page, keyed by label. */
|
|
93
|
+
active_gtag_ids: Record<string, string> | null;
|
|
81
94
|
}
|
|
82
95
|
/**
|
|
83
96
|
* Session payload sent to `POST /tracking/events`.
|
|
@@ -127,6 +140,13 @@ interface TrackingInitConfig {
|
|
|
127
140
|
endpoint?: string;
|
|
128
141
|
/** Optional Google Ads tag id, for example `AW-123456789`. */
|
|
129
142
|
gtagId?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
|
|
145
|
+
* When provided, `gtagId` is ignored.
|
|
146
|
+
*/
|
|
147
|
+
gtagIds?: GtagEnvironmentMap;
|
|
148
|
+
/** Deployment environment label reported in session context. */
|
|
149
|
+
environment?: TrackingEnvironment;
|
|
130
150
|
/** Whether to capture attribution params from `window.location`. Defaults to true. */
|
|
131
151
|
autoCaptureTrackingParams?: boolean;
|
|
132
152
|
/** Whether the browser script should inject the default consent banner. */
|
|
@@ -174,6 +194,8 @@ interface TrackingContextInput {
|
|
|
174
194
|
referrer?: string | null;
|
|
175
195
|
sdkVersion?: string | null;
|
|
176
196
|
siteOrigin?: string | null;
|
|
197
|
+
environment?: TrackingEnvironment;
|
|
198
|
+
activeGtagIds?: Record<string, string> | null;
|
|
177
199
|
}
|
|
178
200
|
interface TrackingEventInput {
|
|
179
201
|
eventType: string;
|
|
@@ -275,6 +297,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
275
297
|
manual: string[];
|
|
276
298
|
}>;
|
|
277
299
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
300
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
278
301
|
}, "strict", z.ZodTypeAny, {
|
|
279
302
|
sdk_version: string;
|
|
280
303
|
package_name: string | null;
|
|
@@ -284,6 +307,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
284
307
|
manual: string[];
|
|
285
308
|
};
|
|
286
309
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
310
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
287
311
|
}, {
|
|
288
312
|
sdk_version: string;
|
|
289
313
|
package_name: string | null;
|
|
@@ -293,6 +317,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
293
317
|
manual: string[];
|
|
294
318
|
};
|
|
295
319
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
320
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
296
321
|
}>;
|
|
297
322
|
type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
|
|
298
323
|
/**
|
|
@@ -1028,6 +1053,7 @@ declare const EVENT_REGISTRY: {
|
|
|
1028
1053
|
manual: string[];
|
|
1029
1054
|
}>;
|
|
1030
1055
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
1056
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
1031
1057
|
}, "strict", z.ZodTypeAny, {
|
|
1032
1058
|
sdk_version: string;
|
|
1033
1059
|
package_name: string | null;
|
|
@@ -1037,6 +1063,7 @@ declare const EVENT_REGISTRY: {
|
|
|
1037
1063
|
manual: string[];
|
|
1038
1064
|
};
|
|
1039
1065
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
1066
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
1040
1067
|
}, {
|
|
1041
1068
|
sdk_version: string;
|
|
1042
1069
|
package_name: string | null;
|
|
@@ -1046,6 +1073,7 @@ declare const EVENT_REGISTRY: {
|
|
|
1046
1073
|
manual: string[];
|
|
1047
1074
|
};
|
|
1048
1075
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
1076
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
1049
1077
|
}>;
|
|
1050
1078
|
readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
1051
1079
|
};
|
|
@@ -1370,6 +1398,27 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
|
1370
1398
|
getVisitorId(): string;
|
|
1371
1399
|
}
|
|
1372
1400
|
|
|
1401
|
+
/**
|
|
1402
|
+
* Props for the Google Ads tracking component.
|
|
1403
|
+
*
|
|
1404
|
+
* Accepts either a single `gtagId` (legacy) or a labelled `gtagIds` map
|
|
1405
|
+
* where ALL entries are loaded simultaneously via `gtag('config', ...)`.
|
|
1406
|
+
*/
|
|
1407
|
+
type GoogleAdsTrackingProps = {
|
|
1408
|
+
gtagId: string;
|
|
1409
|
+
gtagIds?: undefined;
|
|
1410
|
+
} | {
|
|
1411
|
+
gtagId?: undefined;
|
|
1412
|
+
gtagIds: GtagEnvironmentMap;
|
|
1413
|
+
};
|
|
1414
|
+
/**
|
|
1415
|
+
* Client component that loads Google Ads gtag and restores stored consent.
|
|
1416
|
+
*
|
|
1417
|
+
* Render once near the application root when the client site runs paid Google
|
|
1418
|
+
* Ads. The component renders nothing.
|
|
1419
|
+
*/
|
|
1420
|
+
declare function GoogleAdsTracking(props: GoogleAdsTrackingProps): null;
|
|
1421
|
+
|
|
1373
1422
|
/**
|
|
1374
1423
|
* Read the captured Google Ads click id from first-party cookies.
|
|
1375
1424
|
*
|
|
@@ -1408,6 +1457,14 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
|
1408
1457
|
* `automatic.page_view` is required — every tracking install needs it.
|
|
1409
1458
|
*/
|
|
1410
1459
|
triggers: TRegistry;
|
|
1460
|
+
/**
|
|
1461
|
+
* Deployment environment label reported in session context.
|
|
1462
|
+
*
|
|
1463
|
+
* Does not affect which gtag IDs are loaded — all configured IDs are
|
|
1464
|
+
* loaded simultaneously. This value is purely for event tagging so the
|
|
1465
|
+
* dashboard can filter by environment.
|
|
1466
|
+
*/
|
|
1467
|
+
environment?: TrackingEnvironment;
|
|
1411
1468
|
/**
|
|
1412
1469
|
* When true, the typed client validates every `trackEvent()` metadata
|
|
1413
1470
|
* payload through the Zod schema before forwarding. Errors are thrown
|
|
@@ -1419,9 +1476,14 @@ interface TrackingProviderProps {
|
|
|
1419
1476
|
/**
|
|
1420
1477
|
* Optional Google Ads tag id, for example `AW-123456789`.
|
|
1421
1478
|
*
|
|
1422
|
-
* If omitted, no gtag script is loaded
|
|
1479
|
+
* If omitted and `gtagIds` is also omitted, no gtag script is loaded.
|
|
1423
1480
|
*/
|
|
1424
1481
|
gtagId?: string;
|
|
1482
|
+
/**
|
|
1483
|
+
* Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
|
|
1484
|
+
* When provided, `gtagId` is ignored.
|
|
1485
|
+
*/
|
|
1486
|
+
gtagIds?: GtagEnvironmentMap;
|
|
1425
1487
|
/**
|
|
1426
1488
|
* Application tree that should have access to the scoped tracking client.
|
|
1427
1489
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -11,20 +11,6 @@ import { z } from 'zod';
|
|
|
11
11
|
*/
|
|
12
12
|
declare function ConsentBanner(): react_jsx_runtime.JSX.Element | null;
|
|
13
13
|
|
|
14
|
-
interface GoogleAdsTrackingProps {
|
|
15
|
-
/**
|
|
16
|
-
* Google Ads tag id, for example `AW-123456789`.
|
|
17
|
-
*/
|
|
18
|
-
gtagId: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Client component that loads Google Ads gtag and restores stored consent.
|
|
22
|
-
*
|
|
23
|
-
* Render once near the application root when the client site runs paid Google
|
|
24
|
-
* Ads. The component renders nothing.
|
|
25
|
-
*/
|
|
26
|
-
declare function GoogleAdsTracking({ gtagId }: GoogleAdsTrackingProps): null;
|
|
27
|
-
|
|
28
14
|
/**
|
|
29
15
|
* Visitor consent state stored by the SDK.
|
|
30
16
|
*
|
|
@@ -62,6 +48,23 @@ interface TrackingParams {
|
|
|
62
48
|
* whether a site uses the Next, React, or script-tag integration.
|
|
63
49
|
*/
|
|
64
50
|
type TrackingInstallSurface = 'next' | 'react' | 'script';
|
|
51
|
+
/**
|
|
52
|
+
* Deployment environment label for event tagging.
|
|
53
|
+
*
|
|
54
|
+
* Used to stamp tracking events with the deployment context so the dashboard
|
|
55
|
+
* can distinguish production traffic from dev test traffic. The backend
|
|
56
|
+
* enforces this via a Postgres enum, so values are strictly one of
|
|
57
|
+
* `'production'` or `'development'`.
|
|
58
|
+
*/
|
|
59
|
+
type TrackingEnvironment = 'production' | 'development';
|
|
60
|
+
/**
|
|
61
|
+
* Labelled map of Google Ads tag IDs.
|
|
62
|
+
*
|
|
63
|
+
* ALL entries are loaded simultaneously via `gtag('config', ...)` — the keys
|
|
64
|
+
* are human-readable labels (e.g. `production`, `test`) and the values are
|
|
65
|
+
* Google Ads tag IDs (e.g. `AW-123456789`).
|
|
66
|
+
*/
|
|
67
|
+
type GtagEnvironmentMap = Record<string, string>;
|
|
65
68
|
/**
|
|
66
69
|
* Runtime context attached to tracking sessions and events.
|
|
67
70
|
*/
|
|
@@ -78,6 +81,16 @@ interface TrackingClientContext {
|
|
|
78
81
|
page_title: string | null;
|
|
79
82
|
/** Browser document referrer at client creation time. */
|
|
80
83
|
referrer: string | null;
|
|
84
|
+
/**
|
|
85
|
+
* Deployment environment label, e.g. `'production'`, `'development'`.
|
|
86
|
+
*
|
|
87
|
+
* Always set — defaults to `'production'` when the consumer doesn't
|
|
88
|
+
* pass `environment` to the factory. Sending `null` would fail the
|
|
89
|
+
* backend's strict enum validation.
|
|
90
|
+
*/
|
|
91
|
+
environment: TrackingEnvironment;
|
|
92
|
+
/** All active gtag IDs loaded on this page, keyed by label. */
|
|
93
|
+
active_gtag_ids: Record<string, string> | null;
|
|
81
94
|
}
|
|
82
95
|
/**
|
|
83
96
|
* Session payload sent to `POST /tracking/events`.
|
|
@@ -127,6 +140,13 @@ interface TrackingInitConfig {
|
|
|
127
140
|
endpoint?: string;
|
|
128
141
|
/** Optional Google Ads tag id, for example `AW-123456789`. */
|
|
129
142
|
gtagId?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
|
|
145
|
+
* When provided, `gtagId` is ignored.
|
|
146
|
+
*/
|
|
147
|
+
gtagIds?: GtagEnvironmentMap;
|
|
148
|
+
/** Deployment environment label reported in session context. */
|
|
149
|
+
environment?: TrackingEnvironment;
|
|
130
150
|
/** Whether to capture attribution params from `window.location`. Defaults to true. */
|
|
131
151
|
autoCaptureTrackingParams?: boolean;
|
|
132
152
|
/** Whether the browser script should inject the default consent banner. */
|
|
@@ -174,6 +194,8 @@ interface TrackingContextInput {
|
|
|
174
194
|
referrer?: string | null;
|
|
175
195
|
sdkVersion?: string | null;
|
|
176
196
|
siteOrigin?: string | null;
|
|
197
|
+
environment?: TrackingEnvironment;
|
|
198
|
+
activeGtagIds?: Record<string, string> | null;
|
|
177
199
|
}
|
|
178
200
|
interface TrackingEventInput {
|
|
179
201
|
eventType: string;
|
|
@@ -275,6 +297,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
275
297
|
manual: string[];
|
|
276
298
|
}>;
|
|
277
299
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
300
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
278
301
|
}, "strict", z.ZodTypeAny, {
|
|
279
302
|
sdk_version: string;
|
|
280
303
|
package_name: string | null;
|
|
@@ -284,6 +307,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
284
307
|
manual: string[];
|
|
285
308
|
};
|
|
286
309
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
310
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
287
311
|
}, {
|
|
288
312
|
sdk_version: string;
|
|
289
313
|
package_name: string | null;
|
|
@@ -293,6 +317,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
293
317
|
manual: string[];
|
|
294
318
|
};
|
|
295
319
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
320
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
296
321
|
}>;
|
|
297
322
|
type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
|
|
298
323
|
/**
|
|
@@ -1028,6 +1053,7 @@ declare const EVENT_REGISTRY: {
|
|
|
1028
1053
|
manual: string[];
|
|
1029
1054
|
}>;
|
|
1030
1055
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
1056
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
1031
1057
|
}, "strict", z.ZodTypeAny, {
|
|
1032
1058
|
sdk_version: string;
|
|
1033
1059
|
package_name: string | null;
|
|
@@ -1037,6 +1063,7 @@ declare const EVENT_REGISTRY: {
|
|
|
1037
1063
|
manual: string[];
|
|
1038
1064
|
};
|
|
1039
1065
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
1066
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
1040
1067
|
}, {
|
|
1041
1068
|
sdk_version: string;
|
|
1042
1069
|
package_name: string | null;
|
|
@@ -1046,6 +1073,7 @@ declare const EVENT_REGISTRY: {
|
|
|
1046
1073
|
manual: string[];
|
|
1047
1074
|
};
|
|
1048
1075
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
1076
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
1049
1077
|
}>;
|
|
1050
1078
|
readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
1051
1079
|
};
|
|
@@ -1370,6 +1398,27 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
|
1370
1398
|
getVisitorId(): string;
|
|
1371
1399
|
}
|
|
1372
1400
|
|
|
1401
|
+
/**
|
|
1402
|
+
* Props for the Google Ads tracking component.
|
|
1403
|
+
*
|
|
1404
|
+
* Accepts either a single `gtagId` (legacy) or a labelled `gtagIds` map
|
|
1405
|
+
* where ALL entries are loaded simultaneously via `gtag('config', ...)`.
|
|
1406
|
+
*/
|
|
1407
|
+
type GoogleAdsTrackingProps = {
|
|
1408
|
+
gtagId: string;
|
|
1409
|
+
gtagIds?: undefined;
|
|
1410
|
+
} | {
|
|
1411
|
+
gtagId?: undefined;
|
|
1412
|
+
gtagIds: GtagEnvironmentMap;
|
|
1413
|
+
};
|
|
1414
|
+
/**
|
|
1415
|
+
* Client component that loads Google Ads gtag and restores stored consent.
|
|
1416
|
+
*
|
|
1417
|
+
* Render once near the application root when the client site runs paid Google
|
|
1418
|
+
* Ads. The component renders nothing.
|
|
1419
|
+
*/
|
|
1420
|
+
declare function GoogleAdsTracking(props: GoogleAdsTrackingProps): null;
|
|
1421
|
+
|
|
1373
1422
|
/**
|
|
1374
1423
|
* Read the captured Google Ads click id from first-party cookies.
|
|
1375
1424
|
*
|
|
@@ -1408,6 +1457,14 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
|
1408
1457
|
* `automatic.page_view` is required — every tracking install needs it.
|
|
1409
1458
|
*/
|
|
1410
1459
|
triggers: TRegistry;
|
|
1460
|
+
/**
|
|
1461
|
+
* Deployment environment label reported in session context.
|
|
1462
|
+
*
|
|
1463
|
+
* Does not affect which gtag IDs are loaded — all configured IDs are
|
|
1464
|
+
* loaded simultaneously. This value is purely for event tagging so the
|
|
1465
|
+
* dashboard can filter by environment.
|
|
1466
|
+
*/
|
|
1467
|
+
environment?: TrackingEnvironment;
|
|
1411
1468
|
/**
|
|
1412
1469
|
* When true, the typed client validates every `trackEvent()` metadata
|
|
1413
1470
|
* payload through the Zod schema before forwarding. Errors are thrown
|
|
@@ -1419,9 +1476,14 @@ interface TrackingProviderProps {
|
|
|
1419
1476
|
/**
|
|
1420
1477
|
* Optional Google Ads tag id, for example `AW-123456789`.
|
|
1421
1478
|
*
|
|
1422
|
-
* If omitted, no gtag script is loaded
|
|
1479
|
+
* If omitted and `gtagIds` is also omitted, no gtag script is loaded.
|
|
1423
1480
|
*/
|
|
1424
1481
|
gtagId?: string;
|
|
1482
|
+
/**
|
|
1483
|
+
* Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
|
|
1484
|
+
* When provided, `gtagId` is ignored.
|
|
1485
|
+
*/
|
|
1486
|
+
gtagIds?: GtagEnvironmentMap;
|
|
1425
1487
|
/**
|
|
1426
1488
|
* Application tree that should have access to the scoped tracking client.
|
|
1427
1489
|
*/
|
package/dist/index.js
CHANGED
|
@@ -81,7 +81,9 @@ function createTrackingClientContext(surface, input = {}) {
|
|
|
81
81
|
package_name: input.packageName ?? null,
|
|
82
82
|
site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
|
|
83
83
|
page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
|
|
84
|
-
referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null)
|
|
84
|
+
referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
|
|
85
|
+
environment: input.environment ?? "production",
|
|
86
|
+
active_gtag_ids: input.activeGtagIds ?? null
|
|
85
87
|
};
|
|
86
88
|
}
|
|
87
89
|
function createTrackingSessionUpsertPayload(trackingParams, input, context) {
|
|
@@ -118,6 +120,10 @@ var TRACKING_SCRIPT_ATTRIBUTE = "data-aranova-tracking";
|
|
|
118
120
|
function getScriptMarker(id) {
|
|
119
121
|
return `aranova-${id}`;
|
|
120
122
|
}
|
|
123
|
+
var GTAG_ID_PATTERN = /^[A-Z]{1,3}-[A-Za-z0-9_-]+$/;
|
|
124
|
+
function isValidGtagId(id) {
|
|
125
|
+
return GTAG_ID_PATTERN.test(id);
|
|
126
|
+
}
|
|
121
127
|
function ensureGtagFunction() {
|
|
122
128
|
window.dataLayer = window.dataLayer || [];
|
|
123
129
|
if (typeof window.gtag === "function")
|
|
@@ -158,11 +164,28 @@ function initializeGtag(gtagId) {
|
|
|
158
164
|
function bootstrapGoogleAdsTracking(gtagId) {
|
|
159
165
|
if (typeof window === "undefined" || typeof document === "undefined")
|
|
160
166
|
return;
|
|
167
|
+
if (!isValidGtagId(gtagId))
|
|
168
|
+
return;
|
|
161
169
|
applyDefaultConsentState();
|
|
162
170
|
loadGtagScript(gtagId);
|
|
163
171
|
initializeGtag(gtagId);
|
|
164
172
|
restoreStoredConsent();
|
|
165
173
|
}
|
|
174
|
+
function bootstrapMultipleGtags(gtagIds) {
|
|
175
|
+
if (typeof window === "undefined" || typeof document === "undefined")
|
|
176
|
+
return;
|
|
177
|
+
const ids = Object.values(gtagIds).filter(isValidGtagId);
|
|
178
|
+
if (ids.length === 0)
|
|
179
|
+
return;
|
|
180
|
+
applyDefaultConsentState();
|
|
181
|
+
loadGtagScript(ids[0]);
|
|
182
|
+
const gtag = ensureGtagFunction();
|
|
183
|
+
gtag("js", /* @__PURE__ */ new Date());
|
|
184
|
+
for (const id of ids) {
|
|
185
|
+
gtag("config", id);
|
|
186
|
+
}
|
|
187
|
+
restoreStoredConsent();
|
|
188
|
+
}
|
|
166
189
|
|
|
167
190
|
// ../tracking-core/src/tracking.ts
|
|
168
191
|
var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
|
|
@@ -437,7 +460,7 @@ function serializeValue(value) {
|
|
|
437
460
|
}
|
|
438
461
|
return value;
|
|
439
462
|
}
|
|
440
|
-
function buildHeartbeatMetadata(surface, sdkVersion, packageName, triggers) {
|
|
463
|
+
function buildHeartbeatMetadata(surface, sdkVersion, packageName, triggers, gtagIds = null) {
|
|
441
464
|
const automaticNames = triggers ? Object.keys(triggers.automatic) : [];
|
|
442
465
|
const manualNames = triggers?.manual ? Object.keys(triggers.manual) : [];
|
|
443
466
|
let triggerConfig = null;
|
|
@@ -470,7 +493,8 @@ function buildHeartbeatMetadata(surface, sdkVersion, packageName, triggers) {
|
|
|
470
493
|
automatic: automaticNames,
|
|
471
494
|
manual: manualNames
|
|
472
495
|
},
|
|
473
|
-
trigger_config: triggerConfig
|
|
496
|
+
trigger_config: triggerConfig,
|
|
497
|
+
configured_gtag_ids: gtagIds
|
|
474
498
|
};
|
|
475
499
|
}
|
|
476
500
|
|
|
@@ -479,14 +503,16 @@ var DEFAULT_FLUSH_INTERVAL_MS = 2e3;
|
|
|
479
503
|
var DEFAULT_MAX_QUEUE_SIZE = 10;
|
|
480
504
|
var HARD_MAX_BATCH = 50;
|
|
481
505
|
var API_KEY_HEADER = "X-Aranova-Api-Key";
|
|
482
|
-
function buildContext(surface, sdkVersion, packageName) {
|
|
506
|
+
function buildContext(surface, sdkVersion, packageName, environment, activeGtagIds) {
|
|
483
507
|
return {
|
|
484
508
|
surface,
|
|
485
509
|
sdk_version: sdkVersion,
|
|
486
510
|
package_name: packageName,
|
|
487
511
|
site_origin: typeof window === "undefined" ? null : window.location.origin,
|
|
488
512
|
page_title: typeof document === "undefined" ? null : document.title || null,
|
|
489
|
-
referrer: typeof document === "undefined" ? null : document.referrer || null
|
|
513
|
+
referrer: typeof document === "undefined" ? null : document.referrer || null,
|
|
514
|
+
environment,
|
|
515
|
+
active_gtag_ids: activeGtagIds
|
|
490
516
|
};
|
|
491
517
|
}
|
|
492
518
|
function readTrackingParams() {
|
|
@@ -546,6 +572,8 @@ function createTrackingClient(config) {
|
|
|
546
572
|
const maxQueueSize = Math.min(config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, HARD_MAX_BATCH);
|
|
547
573
|
const sdkVersion = config.sdkVersion ?? null;
|
|
548
574
|
const packageName = config.packageName ?? null;
|
|
575
|
+
const environment = config.environment ?? "production";
|
|
576
|
+
const activeGtagIds = config.activeGtagIds ?? null;
|
|
549
577
|
const endpointBase = config.endpoint.replace(/\/$/, "");
|
|
550
578
|
const eventsUrl = `${endpointBase}/events`;
|
|
551
579
|
let queue = [];
|
|
@@ -562,7 +590,8 @@ function createTrackingClient(config) {
|
|
|
562
590
|
config.surface,
|
|
563
591
|
sdkVersion,
|
|
564
592
|
packageName,
|
|
565
|
-
config.triggers ?? null
|
|
593
|
+
config.triggers ?? null,
|
|
594
|
+
activeGtagIds
|
|
566
595
|
);
|
|
567
596
|
queue.push({
|
|
568
597
|
event_type: "sdk_heartbeat",
|
|
@@ -581,7 +610,7 @@ function createTrackingClient(config) {
|
|
|
581
610
|
}
|
|
582
611
|
sessionId = rotated.id;
|
|
583
612
|
const params = readTrackingParams();
|
|
584
|
-
const context = buildContext(config.surface, sdkVersion, packageName);
|
|
613
|
+
const context = buildContext(config.surface, sdkVersion, packageName, environment, activeGtagIds);
|
|
585
614
|
return {
|
|
586
615
|
session_id: sessionId,
|
|
587
616
|
visitor_id: visitorId,
|
|
@@ -703,7 +732,8 @@ var sdkHeartbeatMetadataSchema = import_zod3.z.object({
|
|
|
703
732
|
package_name: import_zod3.z.string().nullable(),
|
|
704
733
|
surface: import_zod3.z.enum(["next", "react", "script"]),
|
|
705
734
|
triggers: sdkHeartbeatTriggersSchema,
|
|
706
|
-
trigger_config: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown())).nullable().optional()
|
|
735
|
+
trigger_config: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown())).nullable().optional(),
|
|
736
|
+
configured_gtag_ids: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.string()).nullable().optional()
|
|
707
737
|
}).strict();
|
|
708
738
|
var sdkHeartbeatConfigSchema = import_zod3.z.object({}).strict();
|
|
709
739
|
|
|
@@ -1293,10 +1323,19 @@ function ConsentBanner() {
|
|
|
1293
1323
|
|
|
1294
1324
|
// src/GoogleAdsTracking.tsx
|
|
1295
1325
|
var import_react2 = require("react");
|
|
1296
|
-
function GoogleAdsTracking(
|
|
1326
|
+
function GoogleAdsTracking(props) {
|
|
1327
|
+
const { gtagId, gtagIds } = props;
|
|
1328
|
+
const gtagIdsKey = (0, import_react2.useMemo)(
|
|
1329
|
+
() => gtagIds ? JSON.stringify(gtagIds) : "",
|
|
1330
|
+
[gtagIds]
|
|
1331
|
+
);
|
|
1297
1332
|
(0, import_react2.useEffect)(() => {
|
|
1298
|
-
|
|
1299
|
-
|
|
1333
|
+
if (gtagIds && Object.keys(gtagIds).length > 0) {
|
|
1334
|
+
bootstrapMultipleGtags(gtagIds);
|
|
1335
|
+
} else if (gtagId) {
|
|
1336
|
+
bootstrapGoogleAdsTracking(gtagId);
|
|
1337
|
+
}
|
|
1338
|
+
}, [gtagId, gtagIdsKey]);
|
|
1300
1339
|
return null;
|
|
1301
1340
|
}
|
|
1302
1341
|
|
|
@@ -1336,7 +1375,7 @@ function useConsentState() {
|
|
|
1336
1375
|
var import_react4 = require("react");
|
|
1337
1376
|
|
|
1338
1377
|
// package.json
|
|
1339
|
-
var version = "0.
|
|
1378
|
+
var version = "0.7.1";
|
|
1340
1379
|
|
|
1341
1380
|
// src/factory.tsx
|
|
1342
1381
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -1349,7 +1388,7 @@ var NOOP_CLIENT = {
|
|
|
1349
1388
|
getVisitorId: () => ""
|
|
1350
1389
|
};
|
|
1351
1390
|
function createTracking(options) {
|
|
1352
|
-
const { apiKey, endpoint, triggers, debug } = options;
|
|
1391
|
+
const { apiKey, endpoint, triggers, environment, debug } = options;
|
|
1353
1392
|
if (!apiKey || !endpoint) {
|
|
1354
1393
|
if (apiKey || endpoint) {
|
|
1355
1394
|
console.warn(
|
|
@@ -1363,7 +1402,8 @@ function createTracking(options) {
|
|
|
1363
1402
|
};
|
|
1364
1403
|
}
|
|
1365
1404
|
const TrackingContext = (0, import_react4.createContext)(null);
|
|
1366
|
-
function TrackingProvider({ gtagId, children }) {
|
|
1405
|
+
function TrackingProvider({ gtagId, gtagIds, children }) {
|
|
1406
|
+
const resolvedGtagIds = gtagIds ?? (gtagId ? { default: gtagId } : void 0);
|
|
1367
1407
|
const client = (0, import_react4.useMemo)(
|
|
1368
1408
|
() => createTypedClient(
|
|
1369
1409
|
getOrCreateTrackingClient({
|
|
@@ -1373,6 +1413,8 @@ function createTracking(options) {
|
|
|
1373
1413
|
packageName: "@aranova/tracking-react",
|
|
1374
1414
|
sdkVersion: version,
|
|
1375
1415
|
triggers,
|
|
1416
|
+
environment,
|
|
1417
|
+
activeGtagIds: resolvedGtagIds,
|
|
1376
1418
|
debug
|
|
1377
1419
|
}),
|
|
1378
1420
|
triggers,
|
|
@@ -1380,10 +1422,14 @@ function createTracking(options) {
|
|
|
1380
1422
|
),
|
|
1381
1423
|
[]
|
|
1382
1424
|
);
|
|
1425
|
+
const gtagIdsKey = (0, import_react4.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
|
|
1383
1426
|
(0, import_react4.useEffect)(() => {
|
|
1384
|
-
if (
|
|
1385
|
-
|
|
1386
|
-
|
|
1427
|
+
if (gtagIds && Object.keys(gtagIds).length > 0) {
|
|
1428
|
+
bootstrapMultipleGtags(gtagIds);
|
|
1429
|
+
} else if (gtagId) {
|
|
1430
|
+
bootstrapGoogleAdsTracking(gtagId);
|
|
1431
|
+
}
|
|
1432
|
+
}, [gtagId, gtagIdsKey]);
|
|
1387
1433
|
(0, import_react4.useEffect)(() => {
|
|
1388
1434
|
const detachers = [];
|
|
1389
1435
|
const rawClient = getOrCreateTrackingClient({
|
|
@@ -1392,6 +1438,8 @@ function createTracking(options) {
|
|
|
1392
1438
|
surface: "react",
|
|
1393
1439
|
packageName: "@aranova/tracking-react",
|
|
1394
1440
|
triggers,
|
|
1441
|
+
environment,
|
|
1442
|
+
activeGtagIds: resolvedGtagIds,
|
|
1395
1443
|
debug
|
|
1396
1444
|
});
|
|
1397
1445
|
detachers.push(attachAutoPageView(rawClient));
|