@aranova/tracking-next 0.14.1 → 0.15.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 +24 -50
- package/dist/index.d.mts +93 -97
- package/dist/index.d.ts +93 -97
- package/dist/index.js +239 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -93
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js +0 -73
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +0 -73
- package/dist/middleware.mjs.map +1 -1
- package/dist/{phone-utils-CcU5mwzc.d.mts → phone-utils-DlAQK-gU.d.mts} +127 -6
- package/dist/{phone-utils-CcU5mwzc.d.ts → phone-utils-DlAQK-gU.d.ts} +127 -6
- package/dist/phone.d.mts +1 -1
- package/dist/phone.d.ts +1 -1
- package/dist/phone.js +0 -73
- package/dist/phone.js.map +1 -1
- package/dist/phone.mjs +0 -73
- package/dist/phone.mjs.map +1 -1
- package/dist/{sales-7w7-Ud60.d.mts → sales-Bq7H-Vym.d.mts} +6 -5
- package/dist/{sales-7w7-Ud60.d.ts → sales-Bq7H-Vym.d.ts} +6 -5
- package/dist/sales.d.mts +1 -1
- package/dist/sales.d.ts +1 -1
- package/dist/sales.js +33 -29
- package/dist/sales.js.map +1 -1
- package/dist/sales.mjs +33 -29
- package/dist/sales.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +0 -73
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +0 -73
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(src_exports, {
|
|
|
33
33
|
AdPlatformTracking: () => AdPlatformTracking,
|
|
34
34
|
AranovaApiError: () => AranovaApiError,
|
|
35
35
|
ConsentBanner: () => ConsentBanner,
|
|
36
|
+
DEFAULT_DECLINE_TTL_DAYS: () => DEFAULT_DECLINE_TTL_DAYS,
|
|
36
37
|
DEFAULT_PHONE_COUNTRY: () => DEFAULT_PHONE_COUNTRY,
|
|
37
38
|
GoogleAdsTracking: () => GoogleAdsTracking,
|
|
38
39
|
NAMED_RANGES: () => NAMED_RANGES,
|
|
@@ -52,7 +53,11 @@ __export(src_exports, {
|
|
|
52
53
|
formatPhone: () => formatPhone,
|
|
53
54
|
formatPhoneAsTyped: () => formatPhoneAsTyped,
|
|
54
55
|
fromMinor: () => fromMinor,
|
|
56
|
+
getConsentChoice: () => getConsentChoice,
|
|
55
57
|
getConsentState: () => getConsentState,
|
|
58
|
+
onConsentChange: () => onConsentChange,
|
|
59
|
+
optIn: () => optIn,
|
|
60
|
+
optOut: () => optOut,
|
|
56
61
|
parsePhone: () => parsePhone,
|
|
57
62
|
phoneField: () => phoneField,
|
|
58
63
|
resetConsent: () => resetConsent,
|
|
@@ -67,6 +72,7 @@ __export(src_exports, {
|
|
|
67
72
|
toMinor: () => toMinor,
|
|
68
73
|
useConsent: () => useConsent,
|
|
69
74
|
useConsentState: () => useConsentState,
|
|
75
|
+
useCookiePreferences: () => useCookiePreferences,
|
|
70
76
|
useGclid: () => useGclid,
|
|
71
77
|
usePhoneConfig: () => usePhoneConfig,
|
|
72
78
|
usePhoneField: () => usePhoneField,
|
|
@@ -77,13 +83,30 @@ module.exports = __toCommonJS(src_exports);
|
|
|
77
83
|
// ../tracking-core/src/consent.ts
|
|
78
84
|
var CONSENT_STATE_KEY = "consent_state";
|
|
79
85
|
var CONSENT_TIMESTAMP_KEY = "consent_timestamp";
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
var CONSENT_EXPIRES_AT_KEY = "consent_expires_at";
|
|
87
|
+
var DEFAULT_DECLINE_TTL_DAYS = 90;
|
|
88
|
+
var DAY_MS = 864e5;
|
|
89
|
+
var DEFAULT_CHOICE = {
|
|
90
|
+
state: "granted",
|
|
91
|
+
source: "default",
|
|
92
|
+
updatedAt: null,
|
|
93
|
+
expiresAt: null
|
|
94
|
+
};
|
|
95
|
+
var changeListeners = /* @__PURE__ */ new Set();
|
|
96
|
+
function onConsentChange(listener) {
|
|
97
|
+
changeListeners.add(listener);
|
|
83
98
|
return () => {
|
|
84
|
-
|
|
99
|
+
changeListeners.delete(listener);
|
|
85
100
|
};
|
|
86
101
|
}
|
|
102
|
+
function notifyConsentChanged(choice) {
|
|
103
|
+
for (const listener of changeListeners) {
|
|
104
|
+
try {
|
|
105
|
+
listener(choice);
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
87
110
|
function buildConsentPayload(state) {
|
|
88
111
|
return {
|
|
89
112
|
ad_storage: state,
|
|
@@ -92,42 +115,88 @@ function buildConsentPayload(state) {
|
|
|
92
115
|
analytics_storage: state
|
|
93
116
|
};
|
|
94
117
|
}
|
|
95
|
-
function
|
|
96
|
-
if (typeof window === "undefined") return
|
|
118
|
+
function getConsentChoice() {
|
|
119
|
+
if (typeof window === "undefined") return DEFAULT_CHOICE;
|
|
97
120
|
try {
|
|
98
|
-
const
|
|
99
|
-
|
|
121
|
+
const stored = window.localStorage.getItem(CONSENT_STATE_KEY);
|
|
122
|
+
const updatedAt = window.localStorage.getItem(CONSENT_TIMESTAMP_KEY);
|
|
123
|
+
if (stored === "granted")
|
|
124
|
+
return { state: "granted", source: "explicit", updatedAt, expiresAt: null };
|
|
125
|
+
if (stored === "denied") {
|
|
126
|
+
let expiresAt = window.localStorage.getItem(CONSENT_EXPIRES_AT_KEY);
|
|
127
|
+
if (!expiresAt) {
|
|
128
|
+
expiresAt = new Date(Date.now() + DEFAULT_DECLINE_TTL_DAYS * DAY_MS).toISOString();
|
|
129
|
+
try {
|
|
130
|
+
window.localStorage.setItem(CONSENT_EXPIRES_AT_KEY, expiresAt);
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!(Date.parse(expiresAt) <= Date.now()))
|
|
135
|
+
return { state: "denied", source: "explicit", updatedAt, expiresAt };
|
|
136
|
+
}
|
|
100
137
|
} catch {
|
|
101
138
|
}
|
|
102
|
-
return
|
|
139
|
+
return DEFAULT_CHOICE;
|
|
140
|
+
}
|
|
141
|
+
function getConsentState() {
|
|
142
|
+
return getConsentChoice().state;
|
|
103
143
|
}
|
|
104
|
-
function
|
|
144
|
+
function pushConsentToPlatforms(state) {
|
|
105
145
|
if (typeof window === "undefined") return;
|
|
106
|
-
try {
|
|
107
|
-
window.localStorage.setItem(CONSENT_STATE_KEY, state);
|
|
108
|
-
window.localStorage.setItem(CONSENT_TIMESTAMP_KEY, (/* @__PURE__ */ new Date()).toISOString());
|
|
109
|
-
} catch {
|
|
110
|
-
}
|
|
111
146
|
if (typeof window.gtag === "function")
|
|
112
147
|
window.gtag("consent", "update", buildConsentPayload(state));
|
|
113
148
|
if (typeof window.fbq === "function")
|
|
114
149
|
window.fbq("consent", state === "granted" ? "grant" : "revoke");
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
150
|
+
}
|
|
151
|
+
function setConsentState(state, options) {
|
|
152
|
+
if (typeof window === "undefined") return;
|
|
153
|
+
const requestedTtl = options?.declineTtlDays;
|
|
154
|
+
const ttlDays = typeof requestedTtl === "number" && Number.isFinite(requestedTtl) && requestedTtl > 0 ? requestedTtl : DEFAULT_DECLINE_TTL_DAYS;
|
|
155
|
+
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
156
|
+
const expiresAt = state === "denied" ? new Date(Date.now() + ttlDays * DAY_MS).toISOString() : null;
|
|
157
|
+
try {
|
|
158
|
+
window.localStorage.setItem(CONSENT_STATE_KEY, state);
|
|
159
|
+
window.localStorage.setItem(CONSENT_TIMESTAMP_KEY, updatedAt);
|
|
160
|
+
if (expiresAt !== null) {
|
|
161
|
+
window.localStorage.setItem(CONSENT_EXPIRES_AT_KEY, expiresAt);
|
|
162
|
+
} else {
|
|
163
|
+
window.localStorage.removeItem(CONSENT_EXPIRES_AT_KEY);
|
|
121
164
|
}
|
|
165
|
+
} catch {
|
|
122
166
|
}
|
|
167
|
+
pushConsentToPlatforms(state);
|
|
168
|
+
notifyConsentChanged({ state, source: "explicit", updatedAt, expiresAt });
|
|
169
|
+
}
|
|
170
|
+
function optIn() {
|
|
171
|
+
setConsentState("granted");
|
|
172
|
+
}
|
|
173
|
+
function optOut(options) {
|
|
174
|
+
setConsentState("denied", options);
|
|
123
175
|
}
|
|
124
176
|
function resetConsent() {
|
|
125
177
|
if (typeof window === "undefined") return;
|
|
126
178
|
try {
|
|
127
179
|
window.localStorage.removeItem(CONSENT_STATE_KEY);
|
|
128
180
|
window.localStorage.removeItem(CONSENT_TIMESTAMP_KEY);
|
|
181
|
+
window.localStorage.removeItem(CONSENT_EXPIRES_AT_KEY);
|
|
129
182
|
} catch {
|
|
130
183
|
}
|
|
184
|
+
pushConsentToPlatforms("granted");
|
|
185
|
+
notifyConsentChanged(DEFAULT_CHOICE);
|
|
186
|
+
}
|
|
187
|
+
function createEffectiveConsentSnippet() {
|
|
188
|
+
return `
|
|
189
|
+
var aranovaConsent = (function () {
|
|
190
|
+
try {
|
|
191
|
+
if (window.localStorage.getItem('${CONSENT_STATE_KEY}') === 'denied') {
|
|
192
|
+
var exp = window.localStorage.getItem('${CONSENT_EXPIRES_AT_KEY}');
|
|
193
|
+
var expMs = exp ? Date.parse(exp) : NaN;
|
|
194
|
+
if (!(expMs <= Date.now())) return 'denied';
|
|
195
|
+
}
|
|
196
|
+
} catch (e) {}
|
|
197
|
+
return 'granted';
|
|
198
|
+
})();
|
|
199
|
+
`.trim();
|
|
131
200
|
}
|
|
132
201
|
|
|
133
202
|
// ../tracking-core/src/tracking.ts
|
|
@@ -242,12 +311,12 @@ function createConsentDefaultScript() {
|
|
|
242
311
|
window.dataLayer = window.dataLayer || [];
|
|
243
312
|
function gtag(){dataLayer.push(arguments);}
|
|
244
313
|
window.gtag = gtag;
|
|
314
|
+
${createEffectiveConsentSnippet()}
|
|
245
315
|
gtag('consent', 'default', {
|
|
246
|
-
ad_storage:
|
|
247
|
-
ad_user_data:
|
|
248
|
-
ad_personalization:
|
|
249
|
-
analytics_storage:
|
|
250
|
-
wait_for_update: 500,
|
|
316
|
+
ad_storage: aranovaConsent,
|
|
317
|
+
ad_user_data: aranovaConsent,
|
|
318
|
+
ad_personalization: aranovaConsent,
|
|
319
|
+
analytics_storage: aranovaConsent
|
|
251
320
|
});
|
|
252
321
|
`.trim();
|
|
253
322
|
}
|
|
@@ -261,21 +330,6 @@ gtag('js', new Date());
|
|
|
261
330
|
gtag('config', '${gtagId}');
|
|
262
331
|
`.trim();
|
|
263
332
|
}
|
|
264
|
-
function createConsentRestoreScript() {
|
|
265
|
-
return `
|
|
266
|
-
try {
|
|
267
|
-
var consentState = window.localStorage.getItem('consent_state');
|
|
268
|
-
if (window.gtag && (consentState === 'granted' || consentState === 'denied')) {
|
|
269
|
-
window.gtag('consent', 'update', {
|
|
270
|
-
ad_storage: consentState,
|
|
271
|
-
ad_user_data: consentState,
|
|
272
|
-
ad_personalization: consentState,
|
|
273
|
-
analytics_storage: consentState,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
} catch (e) {}
|
|
277
|
-
`.trim();
|
|
278
|
-
}
|
|
279
333
|
var SEND_TO_RE = /^AW-[A-Za-z0-9]+\/[A-Za-z0-9_-]+$/;
|
|
280
334
|
function isValidSendTo(sendTo) {
|
|
281
335
|
return SEND_TO_RE.test(sendTo);
|
|
@@ -354,7 +408,8 @@ document,'script','${FB_EVENTS_SCRIPT_HOST}');`.trim();
|
|
|
354
408
|
}
|
|
355
409
|
function createMetaConsentDefaultScript() {
|
|
356
410
|
return `${fbqStubScript()}
|
|
357
|
-
|
|
411
|
+
${createEffectiveConsentSnippet()}
|
|
412
|
+
fbq('consent', aranovaConsent === 'denied' ? 'revoke' : 'grant');`;
|
|
358
413
|
}
|
|
359
414
|
function createMetaPixelInitScript(pixelId) {
|
|
360
415
|
if (!isValidMetaPixelId(pixelId)) return "";
|
|
@@ -367,14 +422,71 @@ function createMetaPixelInitScriptMulti(pixelIds) {
|
|
|
367
422
|
return `${inits.join("\n")}
|
|
368
423
|
fbq('track', 'PageView');`;
|
|
369
424
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
425
|
+
|
|
426
|
+
// ../tracking-core/src/landing.ts
|
|
427
|
+
var LANDING_STORAGE_KEY = "_aranova_track_landing";
|
|
428
|
+
var memoryRecord = null;
|
|
429
|
+
function sanitizeParams(value) {
|
|
430
|
+
if (typeof value !== "object" || value === null) return {};
|
|
431
|
+
const source = value;
|
|
432
|
+
return TRACKING_PARAM_KEYS.reduce((params, key) => {
|
|
433
|
+
const entry = source[key];
|
|
434
|
+
if (typeof entry === "string" && entry.length > 0) params[key] = entry;
|
|
435
|
+
return params;
|
|
436
|
+
}, {});
|
|
437
|
+
}
|
|
438
|
+
function readStoredRecord() {
|
|
439
|
+
try {
|
|
440
|
+
const raw = window.localStorage.getItem(LANDING_STORAGE_KEY);
|
|
441
|
+
if (!raw) return null;
|
|
442
|
+
const parsed = JSON.parse(raw);
|
|
443
|
+
if (typeof parsed.session_id !== "string" || parsed.session_id.length === 0) return null;
|
|
444
|
+
return { session_id: parsed.session_id, params: sanitizeParams(parsed.params) };
|
|
445
|
+
} catch {
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function writeRecord(record) {
|
|
450
|
+
memoryRecord = record;
|
|
451
|
+
try {
|
|
452
|
+
window.localStorage.setItem(LANDING_STORAGE_KEY, JSON.stringify(record));
|
|
453
|
+
} catch {
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function captureFromUrl(url) {
|
|
457
|
+
try {
|
|
458
|
+
const resolved = new URL(url ?? window.location.href, window.location.origin);
|
|
459
|
+
return getTrackingQueryValues(resolved.searchParams);
|
|
460
|
+
} catch {
|
|
461
|
+
return {};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function getOrCaptureLandingParams(sessionId, url) {
|
|
465
|
+
if (typeof window === "undefined") return {};
|
|
466
|
+
const stored = readStoredRecord();
|
|
467
|
+
if (stored && stored.session_id === sessionId) {
|
|
468
|
+
memoryRecord = stored;
|
|
469
|
+
return stored.params;
|
|
470
|
+
}
|
|
471
|
+
if (memoryRecord && memoryRecord.session_id === sessionId) {
|
|
472
|
+
return memoryRecord.params;
|
|
376
473
|
}
|
|
377
|
-
|
|
474
|
+
const record = { session_id: sessionId, params: captureFromUrl(url) };
|
|
475
|
+
writeRecord(record);
|
|
476
|
+
return record.params;
|
|
477
|
+
}
|
|
478
|
+
function buildLandingPayloadFields(sessionId, override) {
|
|
479
|
+
const params = override ?? (typeof window === "undefined" ? null : getOrCaptureLandingParams(sessionId));
|
|
480
|
+
if (params === null) return {};
|
|
481
|
+
return {
|
|
482
|
+
landing_gclid: params.gclid ?? null,
|
|
483
|
+
landing_fbclid: params.fbclid ?? null,
|
|
484
|
+
landing_utm_source: params.utm_source ?? null,
|
|
485
|
+
landing_utm_medium: params.utm_medium ?? null,
|
|
486
|
+
landing_utm_campaign: params.utm_campaign ?? null,
|
|
487
|
+
landing_utm_term: params.utm_term ?? null,
|
|
488
|
+
landing_utm_content: params.utm_content ?? null
|
|
489
|
+
};
|
|
378
490
|
}
|
|
379
491
|
|
|
380
492
|
// ../tracking-core/src/payloads.ts
|
|
@@ -403,6 +515,9 @@ function createTrackingSessionUpsertPayload(trackingParams, input, context) {
|
|
|
403
515
|
utm_campaign: trackingParams.utm_campaign,
|
|
404
516
|
utm_term: trackingParams.utm_term,
|
|
405
517
|
utm_content: trackingParams.utm_content,
|
|
518
|
+
// Omitted entirely when the landing isn't observable (SSR, no override) —
|
|
519
|
+
// present-as-null would wrongly tell the backend "landed with no params".
|
|
520
|
+
...buildLandingPayloadFields(input.sessionId, input.landingParams),
|
|
406
521
|
first_page: input.firstPage ?? null,
|
|
407
522
|
consent_state: input.consentState ?? null,
|
|
408
523
|
context
|
|
@@ -424,8 +539,6 @@ function createTrackingEventCreatePayload(trackingParams, input, context) {
|
|
|
424
539
|
|
|
425
540
|
// ../tracking-core/src/resources/conversion-firing.ts
|
|
426
541
|
var DEDUP_PREFIX = "_aranova_conv_";
|
|
427
|
-
var MAX_PENDING = 100;
|
|
428
|
-
var pendingQueue = [];
|
|
429
542
|
function dedupKey(input) {
|
|
430
543
|
return `${DEDUP_PREFIX}${input.transactionId ?? ""}:${input.sendTo}`;
|
|
431
544
|
}
|
|
@@ -449,23 +562,9 @@ function fireOnce(input) {
|
|
|
449
562
|
if (fireGtagConversion(input)) markFired(input);
|
|
450
563
|
}
|
|
451
564
|
function fireConversionWithConsent(input) {
|
|
452
|
-
|
|
453
|
-
if (state === "denied") return;
|
|
454
|
-
if (state === "pending") {
|
|
455
|
-
if (pendingQueue.length >= MAX_PENDING) pendingQueue.shift();
|
|
456
|
-
pendingQueue.push(input);
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
565
|
+
if (getConsentState() === "denied") return;
|
|
459
566
|
fireOnce(input);
|
|
460
567
|
}
|
|
461
|
-
function flushPendingConversions() {
|
|
462
|
-
if (getConsentState() !== "granted") return;
|
|
463
|
-
while (pendingQueue.length > 0) {
|
|
464
|
-
const input = pendingQueue.shift();
|
|
465
|
-
if (input) fireOnce(input);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
if (typeof window !== "undefined") onConsentGranted(flushPendingConversions);
|
|
469
568
|
|
|
470
569
|
// ../tracking-core/src/resources/conversion-config.ts
|
|
471
570
|
function isStringMap(value) {
|
|
@@ -973,7 +1072,13 @@ function readTrackingParams() {
|
|
|
973
1072
|
}
|
|
974
1073
|
function consentSnapshot() {
|
|
975
1074
|
try {
|
|
976
|
-
|
|
1075
|
+
const choice = getConsentChoice();
|
|
1076
|
+
return {
|
|
1077
|
+
state: choice.state,
|
|
1078
|
+
source: choice.source,
|
|
1079
|
+
updated_at: choice.updatedAt,
|
|
1080
|
+
expires_at: choice.expiresAt
|
|
1081
|
+
};
|
|
977
1082
|
} catch {
|
|
978
1083
|
return null;
|
|
979
1084
|
}
|
|
@@ -1046,6 +1151,7 @@ function createTrackingClient(config) {
|
|
|
1046
1151
|
initialParams = captureTrackingParamsFromLocation();
|
|
1047
1152
|
} catch {
|
|
1048
1153
|
}
|
|
1154
|
+
getOrCaptureLandingParams(sessionId);
|
|
1049
1155
|
try {
|
|
1050
1156
|
captureFbc();
|
|
1051
1157
|
} catch {
|
|
@@ -1095,6 +1201,11 @@ function createTrackingClient(config) {
|
|
|
1095
1201
|
utm_campaign: params.utm_campaign,
|
|
1096
1202
|
utm_term: params.utm_term,
|
|
1097
1203
|
utm_content: params.utm_content,
|
|
1204
|
+
// Landing params for the CURRENT session id — captured on the spot when
|
|
1205
|
+
// the session just rotated (the current URL is the rotated session's
|
|
1206
|
+
// landing), reused from the stored record otherwise. Keys are omitted
|
|
1207
|
+
// entirely when the landing isn't observable (SSR).
|
|
1208
|
+
...buildLandingPayloadFields(sessionId),
|
|
1098
1209
|
first_page: firstPage,
|
|
1099
1210
|
consent_state: consentSnapshot(),
|
|
1100
1211
|
context
|
|
@@ -1997,36 +2108,68 @@ function useTrackingParams() {
|
|
|
1997
2108
|
}, []);
|
|
1998
2109
|
return trackingParams;
|
|
1999
2110
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2111
|
+
var DEFAULT_CHOICE2 = {
|
|
2112
|
+
state: "granted",
|
|
2113
|
+
source: "default",
|
|
2114
|
+
updatedAt: null,
|
|
2115
|
+
expiresAt: null
|
|
2116
|
+
};
|
|
2117
|
+
function useCookiePreferences(options) {
|
|
2118
|
+
const [choice, setChoice] = (0, import_react.useState)(DEFAULT_CHOICE2);
|
|
2119
|
+
const ttlDays = options?.declineTtlDays;
|
|
2005
2120
|
(0, import_react.useEffect)(() => {
|
|
2006
|
-
|
|
2121
|
+
const sync = () => setChoice(getConsentChoice());
|
|
2122
|
+
sync();
|
|
2007
2123
|
const handleStorage = (event) => {
|
|
2008
|
-
if (event.key === CONSENT_STATE_KEY
|
|
2124
|
+
if (event.key === null || event.key === CONSENT_STATE_KEY || event.key === CONSENT_EXPIRES_AT_KEY || event.key === CONSENT_TIMESTAMP_KEY)
|
|
2125
|
+
sync();
|
|
2009
2126
|
};
|
|
2010
2127
|
window.addEventListener("storage", handleStorage);
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2128
|
+
const unsubscribe = onConsentChange(sync);
|
|
2129
|
+
return () => {
|
|
2130
|
+
window.removeEventListener("storage", handleStorage);
|
|
2131
|
+
unsubscribe();
|
|
2132
|
+
};
|
|
2016
2133
|
}, []);
|
|
2017
|
-
const
|
|
2018
|
-
|
|
2019
|
-
|
|
2134
|
+
const optOutAction = (0, import_react.useCallback)(() => {
|
|
2135
|
+
optOut(ttlDays != null ? { declineTtlDays: ttlDays } : void 0);
|
|
2136
|
+
}, [ttlDays]);
|
|
2137
|
+
const optInAction = (0, import_react.useCallback)(() => {
|
|
2138
|
+
optIn();
|
|
2020
2139
|
}, []);
|
|
2021
2140
|
const reset = (0, import_react.useCallback)(() => {
|
|
2022
2141
|
resetConsent();
|
|
2023
|
-
setState("pending");
|
|
2024
2142
|
}, []);
|
|
2143
|
+
return {
|
|
2144
|
+
state: choice.state,
|
|
2145
|
+
source: choice.source,
|
|
2146
|
+
isDefault: choice.source === "default",
|
|
2147
|
+
isGranted: choice.state === "granted",
|
|
2148
|
+
isDenied: choice.state === "denied",
|
|
2149
|
+
updatedAt: choice.updatedAt,
|
|
2150
|
+
expiresAt: choice.expiresAt,
|
|
2151
|
+
optOut: optOutAction,
|
|
2152
|
+
optIn: optInAction,
|
|
2153
|
+
reset
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
function useConsentState() {
|
|
2157
|
+
return useConsent().state;
|
|
2158
|
+
}
|
|
2159
|
+
function useConsent() {
|
|
2160
|
+
const {
|
|
2161
|
+
state,
|
|
2162
|
+
isGranted,
|
|
2163
|
+
isDenied,
|
|
2164
|
+
optIn: accept,
|
|
2165
|
+
optOut: decline,
|
|
2166
|
+
reset
|
|
2167
|
+
} = useCookiePreferences();
|
|
2025
2168
|
return {
|
|
2026
2169
|
state,
|
|
2027
|
-
isPending:
|
|
2028
|
-
isGranted
|
|
2029
|
-
isDenied
|
|
2170
|
+
isPending: false,
|
|
2171
|
+
isGranted,
|
|
2172
|
+
isDenied,
|
|
2030
2173
|
accept,
|
|
2031
2174
|
decline,
|
|
2032
2175
|
reset
|
|
@@ -2242,13 +2385,11 @@ function AdPlatformTracking({
|
|
|
2242
2385
|
strategy: "afterInteractive"
|
|
2243
2386
|
}
|
|
2244
2387
|
),
|
|
2245
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "gtag-init", strategy: "afterInteractive", children: gtagInitScript })
|
|
2246
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "consent-restore", strategy: "afterInteractive", children: createConsentRestoreScript() })
|
|
2388
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "gtag-init", strategy: "afterInteractive", children: gtagInitScript })
|
|
2247
2389
|
] }) : null,
|
|
2248
2390
|
metaAll.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2249
2391
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "meta-pixel-base", strategy: "afterInteractive", children: createMetaConsentDefaultScript() }),
|
|
2250
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "meta-pixel-init", strategy: "afterInteractive", children: metaInitScript })
|
|
2251
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "meta-pixel-consent-restore", strategy: "afterInteractive", children: createMetaConsentRestoreScript() })
|
|
2392
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_script.default, { id: "meta-pixel-init", strategy: "afterInteractive", children: metaInitScript })
|
|
2252
2393
|
] }) : null
|
|
2253
2394
|
] });
|
|
2254
2395
|
}
|
|
@@ -2271,8 +2412,7 @@ function GoogleAdsTracking(props) {
|
|
|
2271
2412
|
strategy: "afterInteractive"
|
|
2272
2413
|
}
|
|
2273
2414
|
),
|
|
2274
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_script2.default, { id: "gtag-init", strategy: "afterInteractive", children: initScript })
|
|
2275
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_script2.default, { id: "consent-restore", strategy: "afterInteractive", children: createConsentRestoreScript() })
|
|
2415
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_script2.default, { id: "gtag-init", strategy: "afterInteractive", children: initScript })
|
|
2276
2416
|
] });
|
|
2277
2417
|
}
|
|
2278
2418
|
|
|
@@ -2280,7 +2420,7 @@ function GoogleAdsTracking(props) {
|
|
|
2280
2420
|
var import_navigation = require("next/navigation");
|
|
2281
2421
|
|
|
2282
2422
|
// package.json
|
|
2283
|
-
var version = "0.
|
|
2423
|
+
var version = "0.15.0";
|
|
2284
2424
|
|
|
2285
2425
|
// src/factory.tsx
|
|
2286
2426
|
var import_react4 = require("react");
|
|
@@ -2593,6 +2733,7 @@ function createTracking(options) {
|
|
|
2593
2733
|
AdPlatformTracking,
|
|
2594
2734
|
AranovaApiError,
|
|
2595
2735
|
ConsentBanner,
|
|
2736
|
+
DEFAULT_DECLINE_TTL_DAYS,
|
|
2596
2737
|
DEFAULT_PHONE_COUNTRY,
|
|
2597
2738
|
GoogleAdsTracking,
|
|
2598
2739
|
NAMED_RANGES,
|
|
@@ -2612,7 +2753,11 @@ function createTracking(options) {
|
|
|
2612
2753
|
formatPhone,
|
|
2613
2754
|
formatPhoneAsTyped,
|
|
2614
2755
|
fromMinor,
|
|
2756
|
+
getConsentChoice,
|
|
2615
2757
|
getConsentState,
|
|
2758
|
+
onConsentChange,
|
|
2759
|
+
optIn,
|
|
2760
|
+
optOut,
|
|
2616
2761
|
parsePhone,
|
|
2617
2762
|
phoneField,
|
|
2618
2763
|
resetConsent,
|
|
@@ -2627,6 +2772,7 @@ function createTracking(options) {
|
|
|
2627
2772
|
toMinor,
|
|
2628
2773
|
useConsent,
|
|
2629
2774
|
useConsentState,
|
|
2775
|
+
useCookiePreferences,
|
|
2630
2776
|
useGclid,
|
|
2631
2777
|
usePhoneConfig,
|
|
2632
2778
|
usePhoneField,
|