@aranova/tracking-next 0.6.1 → 0.7.0
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 +29 -0
- package/dist/index.d.mts +36 -8
- package/dist/index.d.ts +36 -8
- package/dist/index.js +58 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -13
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js +2 -1
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +2 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +2 -1
- package/dist/server.mjs.map +1 -1
- package/dist/{types-B4VZHWnc.d.mts → types-D0Vm9WRC.d.mts} +29 -1
- package/dist/{types-B4VZHWnc.d.ts → types-D0Vm9WRC.d.ts} +29 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,6 +78,35 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
78
78
|
}
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
+
### Multiple gtag IDs
|
|
82
|
+
|
|
83
|
+
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.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<GoogleAdsTracking
|
|
87
|
+
gtagIds={{
|
|
88
|
+
production: 'AW-111111111', // real client account
|
|
89
|
+
test: 'AW-222222222', // test MCC for development
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The labels are arbitrary and surface in the Aranova dashboard's SDK versions table. Also pass `environment` to the factory so events are tagged with the deployment context for dashboard filtering:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
// lib/tracking.ts
|
|
98
|
+
createTracking({
|
|
99
|
+
apiKey: process.env.NEXT_PUBLIC_ARANOVA_TRACKING_API_KEY!,
|
|
100
|
+
endpoint: process.env.NEXT_PUBLIC_ARANOVA_TRACKING_ENDPOINT!,
|
|
101
|
+
environment: process.env.NEXT_PUBLIC_TRACKING_ENVIRONMENT, // 'production' | 'development'
|
|
102
|
+
gtagIds: { // optional — reports the configured tags in heartbeat metadata
|
|
103
|
+
production: process.env.NEXT_PUBLIC_GTAG_PROD!,
|
|
104
|
+
test: process.env.NEXT_PUBLIC_GTAG_TEST!,
|
|
105
|
+
},
|
|
106
|
+
triggers: { /* ... */ },
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
81
110
|
## Manual Events
|
|
82
111
|
|
|
83
112
|
Import `useTracking` from your local `lib/tracking` module, not directly from the package.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConsentState, T as TrackingInstallSurface, a as
|
|
2
|
-
export {
|
|
1
|
+
import { C as ConsentState, T as TrackingInstallSurface, a as TrackingEnvironment, b as TrackingClientContext, c as TrackingParams, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, G as GtagEnvironmentMap } from './types-D0Vm9WRC.mjs';
|
|
2
|
+
export { f as TrackingInitConfig } from './types-D0Vm9WRC.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as src from 'src';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -28,6 +28,8 @@ interface TrackingContextInput {
|
|
|
28
28
|
referrer?: string | null;
|
|
29
29
|
sdkVersion?: string | null;
|
|
30
30
|
siteOrigin?: string | null;
|
|
31
|
+
environment?: TrackingEnvironment | null;
|
|
32
|
+
activeGtagIds?: Record<string, string> | null;
|
|
31
33
|
}
|
|
32
34
|
interface TrackingEventInput {
|
|
33
35
|
eventType: string;
|
|
@@ -129,6 +131,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
129
131
|
manual: string[];
|
|
130
132
|
}>;
|
|
131
133
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
134
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
132
135
|
}, "strict", z.ZodTypeAny, {
|
|
133
136
|
sdk_version: string;
|
|
134
137
|
package_name: string | null;
|
|
@@ -138,6 +141,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
138
141
|
manual: string[];
|
|
139
142
|
};
|
|
140
143
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
144
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
141
145
|
}, {
|
|
142
146
|
sdk_version: string;
|
|
143
147
|
package_name: string | null;
|
|
@@ -147,6 +151,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
147
151
|
manual: string[];
|
|
148
152
|
};
|
|
149
153
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
154
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
150
155
|
}>;
|
|
151
156
|
type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
|
|
152
157
|
/**
|
|
@@ -882,6 +887,7 @@ declare const EVENT_REGISTRY: {
|
|
|
882
887
|
manual: string[];
|
|
883
888
|
}>;
|
|
884
889
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
890
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
885
891
|
}, "strict", z.ZodTypeAny, {
|
|
886
892
|
sdk_version: string;
|
|
887
893
|
package_name: string | null;
|
|
@@ -891,6 +897,7 @@ declare const EVENT_REGISTRY: {
|
|
|
891
897
|
manual: string[];
|
|
892
898
|
};
|
|
893
899
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
900
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
894
901
|
}, {
|
|
895
902
|
sdk_version: string;
|
|
896
903
|
package_name: string | null;
|
|
@@ -900,6 +907,7 @@ declare const EVENT_REGISTRY: {
|
|
|
900
907
|
manual: string[];
|
|
901
908
|
};
|
|
902
909
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
910
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
903
911
|
}>;
|
|
904
912
|
readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
905
913
|
};
|
|
@@ -1250,19 +1258,26 @@ declare function useTrackingParams(): TrackingParams;
|
|
|
1250
1258
|
*/
|
|
1251
1259
|
declare function useConsentState(): ConsentState;
|
|
1252
1260
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1261
|
+
/**
|
|
1262
|
+
* Props for the Next.js Google Ads tracking component.
|
|
1263
|
+
*
|
|
1264
|
+
* Accepts either a single `gtagId` (legacy) or a labelled `gtagIds` map
|
|
1265
|
+
* where ALL entries are loaded simultaneously via `gtag('config', ...)`.
|
|
1266
|
+
*/
|
|
1267
|
+
type GoogleAdsTrackingProps = {
|
|
1257
1268
|
gtagId: string;
|
|
1258
|
-
|
|
1269
|
+
gtagIds?: undefined;
|
|
1270
|
+
} | {
|
|
1271
|
+
gtagId?: undefined;
|
|
1272
|
+
gtagIds: GtagEnvironmentMap;
|
|
1273
|
+
};
|
|
1259
1274
|
/**
|
|
1260
1275
|
* Next.js client component that loads Google Ads gtag with Consent Mode.
|
|
1261
1276
|
*
|
|
1262
1277
|
* Render in the root layout `<head>` when the client site runs paid Google
|
|
1263
1278
|
* Ads. The component injects Next `<Script>` tags and renders no visible UI.
|
|
1264
1279
|
*/
|
|
1265
|
-
declare function GoogleAdsTracking(
|
|
1280
|
+
declare function GoogleAdsTracking(props: GoogleAdsTrackingProps): react_jsx_runtime.JSX.Element | null;
|
|
1266
1281
|
|
|
1267
1282
|
interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
1268
1283
|
/**
|
|
@@ -1279,6 +1294,19 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
|
1279
1294
|
* Trigger registry that controls automatic events and typed manual events.
|
|
1280
1295
|
*/
|
|
1281
1296
|
triggers: TRegistry;
|
|
1297
|
+
/**
|
|
1298
|
+
* Deployment environment label reported in session context.
|
|
1299
|
+
*/
|
|
1300
|
+
environment?: TrackingEnvironment;
|
|
1301
|
+
/**
|
|
1302
|
+
* Labelled map of Google Ads tag IDs. Included in session context and
|
|
1303
|
+
* heartbeat metadata so the dashboard can show what's configured.
|
|
1304
|
+
*
|
|
1305
|
+
* This does NOT load the gtag scripts — use `<GoogleAdsTracking gtagIds={...} />`
|
|
1306
|
+
* in the root layout for that. This option only controls what's reported
|
|
1307
|
+
* in the tracking payload context.
|
|
1308
|
+
*/
|
|
1309
|
+
gtagIds?: Record<string, string>;
|
|
1282
1310
|
/**
|
|
1283
1311
|
* Validate manual event metadata at runtime before queueing.
|
|
1284
1312
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConsentState, T as TrackingInstallSurface, a as
|
|
2
|
-
export {
|
|
1
|
+
import { C as ConsentState, T as TrackingInstallSurface, a as TrackingEnvironment, b as TrackingClientContext, c as TrackingParams, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, G as GtagEnvironmentMap } from './types-D0Vm9WRC.js';
|
|
2
|
+
export { f as TrackingInitConfig } from './types-D0Vm9WRC.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as src from 'src';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -28,6 +28,8 @@ interface TrackingContextInput {
|
|
|
28
28
|
referrer?: string | null;
|
|
29
29
|
sdkVersion?: string | null;
|
|
30
30
|
siteOrigin?: string | null;
|
|
31
|
+
environment?: TrackingEnvironment | null;
|
|
32
|
+
activeGtagIds?: Record<string, string> | null;
|
|
31
33
|
}
|
|
32
34
|
interface TrackingEventInput {
|
|
33
35
|
eventType: string;
|
|
@@ -129,6 +131,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
129
131
|
manual: string[];
|
|
130
132
|
}>;
|
|
131
133
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
134
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
132
135
|
}, "strict", z.ZodTypeAny, {
|
|
133
136
|
sdk_version: string;
|
|
134
137
|
package_name: string | null;
|
|
@@ -138,6 +141,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
138
141
|
manual: string[];
|
|
139
142
|
};
|
|
140
143
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
144
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
141
145
|
}, {
|
|
142
146
|
sdk_version: string;
|
|
143
147
|
package_name: string | null;
|
|
@@ -147,6 +151,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
147
151
|
manual: string[];
|
|
148
152
|
};
|
|
149
153
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
154
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
150
155
|
}>;
|
|
151
156
|
type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
|
|
152
157
|
/**
|
|
@@ -882,6 +887,7 @@ declare const EVENT_REGISTRY: {
|
|
|
882
887
|
manual: string[];
|
|
883
888
|
}>;
|
|
884
889
|
trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
890
|
+
configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
885
891
|
}, "strict", z.ZodTypeAny, {
|
|
886
892
|
sdk_version: string;
|
|
887
893
|
package_name: string | null;
|
|
@@ -891,6 +897,7 @@ declare const EVENT_REGISTRY: {
|
|
|
891
897
|
manual: string[];
|
|
892
898
|
};
|
|
893
899
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
900
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
894
901
|
}, {
|
|
895
902
|
sdk_version: string;
|
|
896
903
|
package_name: string | null;
|
|
@@ -900,6 +907,7 @@ declare const EVENT_REGISTRY: {
|
|
|
900
907
|
manual: string[];
|
|
901
908
|
};
|
|
902
909
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
910
|
+
configured_gtag_ids?: Record<string, string> | null | undefined;
|
|
903
911
|
}>;
|
|
904
912
|
readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
905
913
|
};
|
|
@@ -1250,19 +1258,26 @@ declare function useTrackingParams(): TrackingParams;
|
|
|
1250
1258
|
*/
|
|
1251
1259
|
declare function useConsentState(): ConsentState;
|
|
1252
1260
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1261
|
+
/**
|
|
1262
|
+
* Props for the Next.js Google Ads tracking component.
|
|
1263
|
+
*
|
|
1264
|
+
* Accepts either a single `gtagId` (legacy) or a labelled `gtagIds` map
|
|
1265
|
+
* where ALL entries are loaded simultaneously via `gtag('config', ...)`.
|
|
1266
|
+
*/
|
|
1267
|
+
type GoogleAdsTrackingProps = {
|
|
1257
1268
|
gtagId: string;
|
|
1258
|
-
|
|
1269
|
+
gtagIds?: undefined;
|
|
1270
|
+
} | {
|
|
1271
|
+
gtagId?: undefined;
|
|
1272
|
+
gtagIds: GtagEnvironmentMap;
|
|
1273
|
+
};
|
|
1259
1274
|
/**
|
|
1260
1275
|
* Next.js client component that loads Google Ads gtag with Consent Mode.
|
|
1261
1276
|
*
|
|
1262
1277
|
* Render in the root layout `<head>` when the client site runs paid Google
|
|
1263
1278
|
* Ads. The component injects Next `<Script>` tags and renders no visible UI.
|
|
1264
1279
|
*/
|
|
1265
|
-
declare function GoogleAdsTracking(
|
|
1280
|
+
declare function GoogleAdsTracking(props: GoogleAdsTrackingProps): react_jsx_runtime.JSX.Element | null;
|
|
1266
1281
|
|
|
1267
1282
|
interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
1268
1283
|
/**
|
|
@@ -1279,6 +1294,19 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
|
1279
1294
|
* Trigger registry that controls automatic events and typed manual events.
|
|
1280
1295
|
*/
|
|
1281
1296
|
triggers: TRegistry;
|
|
1297
|
+
/**
|
|
1298
|
+
* Deployment environment label reported in session context.
|
|
1299
|
+
*/
|
|
1300
|
+
environment?: TrackingEnvironment;
|
|
1301
|
+
/**
|
|
1302
|
+
* Labelled map of Google Ads tag IDs. Included in session context and
|
|
1303
|
+
* heartbeat metadata so the dashboard can show what's configured.
|
|
1304
|
+
*
|
|
1305
|
+
* This does NOT load the gtag scripts — use `<GoogleAdsTracking gtagIds={...} />`
|
|
1306
|
+
* in the root layout for that. This option only controls what's reported
|
|
1307
|
+
* in the tracking payload context.
|
|
1308
|
+
*/
|
|
1309
|
+
gtagIds?: Record<string, string>;
|
|
1282
1310
|
/**
|
|
1283
1311
|
* Validate manual event metadata at runtime before queueing.
|
|
1284
1312
|
*
|
package/dist/index.js
CHANGED
|
@@ -82,7 +82,9 @@ function createTrackingClientContext(surface, input = {}) {
|
|
|
82
82
|
package_name: input.packageName ?? null,
|
|
83
83
|
site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
|
|
84
84
|
page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
|
|
85
|
-
referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null)
|
|
85
|
+
referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
|
|
86
|
+
environment: input.environment ?? null,
|
|
87
|
+
active_gtag_ids: input.activeGtagIds ?? null
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
90
|
function createTrackingSessionUpsertPayload(trackingParams, input, context) {
|
|
@@ -114,6 +116,10 @@ function createTrackingEventCreatePayload(trackingParams, input, context) {
|
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
// ../tracking-core/src/gtag.ts
|
|
119
|
+
var GTAG_ID_PATTERN = /^[A-Z]{1,3}-[A-Za-z0-9_-]+$/;
|
|
120
|
+
function isValidGtagId(id) {
|
|
121
|
+
return GTAG_ID_PATTERN.test(id);
|
|
122
|
+
}
|
|
117
123
|
function createConsentDefaultScript() {
|
|
118
124
|
return `
|
|
119
125
|
window.dataLayer = window.dataLayer || [];
|
|
@@ -129,6 +135,7 @@ gtag('consent', 'default', {
|
|
|
129
135
|
`.trim();
|
|
130
136
|
}
|
|
131
137
|
function createGtagInitScript(gtagId) {
|
|
138
|
+
if (!isValidGtagId(gtagId)) return "";
|
|
132
139
|
return `
|
|
133
140
|
window.dataLayer = window.dataLayer || [];
|
|
134
141
|
function gtag(){dataLayer.push(arguments);}
|
|
@@ -150,6 +157,17 @@ if (window.gtag && (consentState === 'granted' || consentState === 'denied')) {
|
|
|
150
157
|
}
|
|
151
158
|
`.trim();
|
|
152
159
|
}
|
|
160
|
+
function createGtagInitScriptMulti(gtagIds) {
|
|
161
|
+
const safeIds = gtagIds.filter(isValidGtagId);
|
|
162
|
+
const configs = safeIds.map((id) => `gtag('config', '${id}');`).join("\n");
|
|
163
|
+
return `
|
|
164
|
+
window.dataLayer = window.dataLayer || [];
|
|
165
|
+
function gtag(){dataLayer.push(arguments);}
|
|
166
|
+
window.gtag = gtag;
|
|
167
|
+
gtag('js', new Date());
|
|
168
|
+
${configs}
|
|
169
|
+
`.trim();
|
|
170
|
+
}
|
|
153
171
|
|
|
154
172
|
// ../tracking-core/src/tracking.ts
|
|
155
173
|
var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
|
|
@@ -384,7 +402,7 @@ function serializeValue(value) {
|
|
|
384
402
|
}
|
|
385
403
|
return value;
|
|
386
404
|
}
|
|
387
|
-
function buildHeartbeatMetadata(surface, sdkVersion, packageName, triggers) {
|
|
405
|
+
function buildHeartbeatMetadata(surface, sdkVersion, packageName, triggers, gtagIds = null) {
|
|
388
406
|
const automaticNames = triggers ? Object.keys(triggers.automatic) : [];
|
|
389
407
|
const manualNames = triggers?.manual ? Object.keys(triggers.manual) : [];
|
|
390
408
|
let triggerConfig = null;
|
|
@@ -417,7 +435,8 @@ function buildHeartbeatMetadata(surface, sdkVersion, packageName, triggers) {
|
|
|
417
435
|
automatic: automaticNames,
|
|
418
436
|
manual: manualNames
|
|
419
437
|
},
|
|
420
|
-
trigger_config: triggerConfig
|
|
438
|
+
trigger_config: triggerConfig,
|
|
439
|
+
configured_gtag_ids: gtagIds
|
|
421
440
|
};
|
|
422
441
|
}
|
|
423
442
|
|
|
@@ -426,14 +445,16 @@ var DEFAULT_FLUSH_INTERVAL_MS = 2e3;
|
|
|
426
445
|
var DEFAULT_MAX_QUEUE_SIZE = 10;
|
|
427
446
|
var HARD_MAX_BATCH = 50;
|
|
428
447
|
var API_KEY_HEADER = "X-Aranova-Api-Key";
|
|
429
|
-
function buildContext(surface, sdkVersion, packageName) {
|
|
448
|
+
function buildContext(surface, sdkVersion, packageName, environment, activeGtagIds) {
|
|
430
449
|
return {
|
|
431
450
|
surface,
|
|
432
451
|
sdk_version: sdkVersion,
|
|
433
452
|
package_name: packageName,
|
|
434
453
|
site_origin: typeof window === "undefined" ? null : window.location.origin,
|
|
435
454
|
page_title: typeof document === "undefined" ? null : document.title || null,
|
|
436
|
-
referrer: typeof document === "undefined" ? null : document.referrer || null
|
|
455
|
+
referrer: typeof document === "undefined" ? null : document.referrer || null,
|
|
456
|
+
environment,
|
|
457
|
+
active_gtag_ids: activeGtagIds
|
|
437
458
|
};
|
|
438
459
|
}
|
|
439
460
|
function readTrackingParams() {
|
|
@@ -493,6 +514,8 @@ function createTrackingClient(config) {
|
|
|
493
514
|
const maxQueueSize = Math.min(config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, HARD_MAX_BATCH);
|
|
494
515
|
const sdkVersion = config.sdkVersion ?? null;
|
|
495
516
|
const packageName = config.packageName ?? null;
|
|
517
|
+
const environment = config.environment ?? null;
|
|
518
|
+
const activeGtagIds = config.activeGtagIds ?? null;
|
|
496
519
|
const endpointBase = config.endpoint.replace(/\/$/, "");
|
|
497
520
|
const eventsUrl = `${endpointBase}/events`;
|
|
498
521
|
let queue = [];
|
|
@@ -509,7 +532,8 @@ function createTrackingClient(config) {
|
|
|
509
532
|
config.surface,
|
|
510
533
|
sdkVersion,
|
|
511
534
|
packageName,
|
|
512
|
-
config.triggers ?? null
|
|
535
|
+
config.triggers ?? null,
|
|
536
|
+
activeGtagIds
|
|
513
537
|
);
|
|
514
538
|
queue.push({
|
|
515
539
|
event_type: "sdk_heartbeat",
|
|
@@ -528,7 +552,7 @@ function createTrackingClient(config) {
|
|
|
528
552
|
}
|
|
529
553
|
sessionId = rotated.id;
|
|
530
554
|
const params = readTrackingParams();
|
|
531
|
-
const context = buildContext(config.surface, sdkVersion, packageName);
|
|
555
|
+
const context = buildContext(config.surface, sdkVersion, packageName, environment, activeGtagIds);
|
|
532
556
|
return {
|
|
533
557
|
session_id: sessionId,
|
|
534
558
|
visitor_id: visitorId,
|
|
@@ -650,7 +674,8 @@ var sdkHeartbeatMetadataSchema = import_zod3.z.object({
|
|
|
650
674
|
package_name: import_zod3.z.string().nullable(),
|
|
651
675
|
surface: import_zod3.z.enum(["next", "react", "script"]),
|
|
652
676
|
triggers: sdkHeartbeatTriggersSchema,
|
|
653
|
-
trigger_config: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown())).nullable().optional()
|
|
677
|
+
trigger_config: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown())).nullable().optional(),
|
|
678
|
+
configured_gtag_ids: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.string()).nullable().optional()
|
|
654
679
|
}).strict();
|
|
655
680
|
var sdkHeartbeatConfigSchema = import_zod3.z.object({}).strict();
|
|
656
681
|
|
|
@@ -1139,17 +1164,22 @@ function useConsentState() {
|
|
|
1139
1164
|
// src/GoogleAdsTracking.tsx
|
|
1140
1165
|
var import_script = __toESM(require("next/script"));
|
|
1141
1166
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1142
|
-
function GoogleAdsTracking(
|
|
1167
|
+
function GoogleAdsTracking(props) {
|
|
1168
|
+
const { gtagId, gtagIds } = props;
|
|
1169
|
+
const allIds = gtagIds ? Object.values(gtagIds) : gtagId ? [gtagId] : [];
|
|
1170
|
+
if (allIds.length === 0) return null;
|
|
1171
|
+
const loaderId = allIds[0];
|
|
1172
|
+
const initScript = allIds.length === 1 ? createGtagInitScript(allIds[0]) : createGtagInitScriptMulti(allIds);
|
|
1143
1173
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1144
1174
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "consent-default", strategy: "beforeInteractive", children: createConsentDefaultScript() }),
|
|
1145
1175
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1146
1176
|
import_script.default,
|
|
1147
1177
|
{
|
|
1148
|
-
src: `https://www.googletagmanager.com/gtag/js?id=${
|
|
1178
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(loaderId)}`,
|
|
1149
1179
|
strategy: "afterInteractive"
|
|
1150
1180
|
}
|
|
1151
1181
|
),
|
|
1152
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "gtag-init", strategy: "afterInteractive", children:
|
|
1182
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "gtag-init", strategy: "afterInteractive", children: initScript }),
|
|
1153
1183
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "consent-restore", strategy: "afterInteractive", children: createConsentRestoreScript() })
|
|
1154
1184
|
] });
|
|
1155
1185
|
}
|
|
@@ -1158,13 +1188,13 @@ function GoogleAdsTracking({ gtagId }) {
|
|
|
1158
1188
|
var import_navigation = require("next/navigation");
|
|
1159
1189
|
|
|
1160
1190
|
// package.json
|
|
1161
|
-
var version = "0.
|
|
1191
|
+
var version = "0.7.0";
|
|
1162
1192
|
|
|
1163
1193
|
// src/factory.tsx
|
|
1164
1194
|
var import_react3 = require("react");
|
|
1165
1195
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1166
1196
|
function createTracking(options) {
|
|
1167
|
-
const { apiKey, endpoint, triggers, debug } = options;
|
|
1197
|
+
const { apiKey, endpoint, triggers, environment, gtagIds, debug } = options;
|
|
1168
1198
|
if (!apiKey || !endpoint) {
|
|
1169
1199
|
if (apiKey || endpoint) {
|
|
1170
1200
|
console.warn(
|
|
@@ -1199,6 +1229,8 @@ function createTracking(options) {
|
|
|
1199
1229
|
packageName: "@aranova/tracking-next",
|
|
1200
1230
|
sdkVersion: version,
|
|
1201
1231
|
triggers,
|
|
1232
|
+
environment,
|
|
1233
|
+
activeGtagIds: gtagIds,
|
|
1202
1234
|
debug
|
|
1203
1235
|
}),
|
|
1204
1236
|
triggers,
|
|
@@ -1213,6 +1245,8 @@ function createTracking(options) {
|
|
|
1213
1245
|
surface: "next",
|
|
1214
1246
|
packageName: "@aranova/tracking-next",
|
|
1215
1247
|
triggers,
|
|
1248
|
+
environment,
|
|
1249
|
+
activeGtagIds: gtagIds,
|
|
1216
1250
|
debug
|
|
1217
1251
|
});
|
|
1218
1252
|
fireManualPageView(rawClient);
|
|
@@ -1226,6 +1260,8 @@ function createTracking(options) {
|
|
|
1226
1260
|
surface: "next",
|
|
1227
1261
|
packageName: "@aranova/tracking-next",
|
|
1228
1262
|
triggers,
|
|
1263
|
+
environment,
|
|
1264
|
+
activeGtagIds: gtagIds,
|
|
1229
1265
|
debug
|
|
1230
1266
|
});
|
|
1231
1267
|
for (const { name, pathPattern } of specificPageVisitConfig.pages) {
|
|
@@ -1248,6 +1284,8 @@ function createTracking(options) {
|
|
|
1248
1284
|
surface: "next",
|
|
1249
1285
|
packageName: "@aranova/tracking-next",
|
|
1250
1286
|
triggers,
|
|
1287
|
+
environment,
|
|
1288
|
+
activeGtagIds: gtagIds,
|
|
1251
1289
|
debug
|
|
1252
1290
|
});
|
|
1253
1291
|
return attachBfcacheRestore(rawClient);
|
|
@@ -1260,6 +1298,8 @@ function createTracking(options) {
|
|
|
1260
1298
|
surface: "next",
|
|
1261
1299
|
packageName: "@aranova/tracking-next",
|
|
1262
1300
|
triggers,
|
|
1301
|
+
environment,
|
|
1302
|
+
activeGtagIds: gtagIds,
|
|
1263
1303
|
debug
|
|
1264
1304
|
});
|
|
1265
1305
|
return attachTimeOnSite(rawClient, timeOnSiteConfig);
|
|
@@ -1294,7 +1334,10 @@ function createTracking(options) {
|
|
|
1294
1334
|
endpoint,
|
|
1295
1335
|
surface: "next",
|
|
1296
1336
|
packageName: "@aranova/tracking-next",
|
|
1337
|
+
sdkVersion: version,
|
|
1297
1338
|
triggers,
|
|
1339
|
+
environment,
|
|
1340
|
+
activeGtagIds: gtagIds,
|
|
1298
1341
|
debug
|
|
1299
1342
|
});
|
|
1300
1343
|
rawClient.trackEvent({
|
|
@@ -1318,6 +1361,8 @@ function createTracking(options) {
|
|
|
1318
1361
|
surface: "next",
|
|
1319
1362
|
packageName: "@aranova/tracking-next",
|
|
1320
1363
|
triggers,
|
|
1364
|
+
environment,
|
|
1365
|
+
activeGtagIds: gtagIds,
|
|
1321
1366
|
debug
|
|
1322
1367
|
});
|
|
1323
1368
|
const scrollDepth = triggers.automatic.scroll_depth;
|