c15t 1.3.1 → 1.3.3
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/CHANGELOG.md +14 -0
- package/dist/index.cjs +86 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -0
- package/dist/libs/fetch-consent-banner.d.ts +1 -1
- package/dist/libs/fetch-consent-banner.d.ts.map +1 -1
- package/dist/libs/gtm.d.ts +93 -0
- package/dist/libs/gtm.d.ts.map +1 -0
- package/dist/store.d.ts +6 -1
- package/dist/store.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# c15t
|
|
2
2
|
|
|
3
|
+
## 1.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b4d53be: feat(core): added Google Tag Manager support
|
|
8
|
+
fix(react): allow trapFocus={false} in CookieBanner
|
|
9
|
+
fix(nextjs): improved url validation
|
|
10
|
+
|
|
11
|
+
## 1.3.3-canary-20250624131627
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 63200df: feat(core): added Google Tag Manager support
|
|
16
|
+
|
|
3
17
|
## 1.3.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1259,6 +1259,82 @@ const initialState = {
|
|
|
1259
1259
|
hasConsented: ()=>false,
|
|
1260
1260
|
setTranslationConfig: ()=>{}
|
|
1261
1261
|
};
|
|
1262
|
+
const DEFAULT_GTM_CONSENT_CONFIG = {
|
|
1263
|
+
functionality_storage: 'denied',
|
|
1264
|
+
security_storage: 'denied',
|
|
1265
|
+
analytics_storage: 'denied',
|
|
1266
|
+
ad_storage: 'denied',
|
|
1267
|
+
ad_user_data: 'denied',
|
|
1268
|
+
ad_personalization: 'denied',
|
|
1269
|
+
personalization_storage: 'denied'
|
|
1270
|
+
};
|
|
1271
|
+
const CONSENT_STATE_TO_GTM_MAPPING = {
|
|
1272
|
+
necessary: [
|
|
1273
|
+
'security_storage'
|
|
1274
|
+
],
|
|
1275
|
+
functionality: [
|
|
1276
|
+
'functionality_storage'
|
|
1277
|
+
],
|
|
1278
|
+
measurement: [
|
|
1279
|
+
'analytics_storage'
|
|
1280
|
+
],
|
|
1281
|
+
marketing: [
|
|
1282
|
+
'ad_storage',
|
|
1283
|
+
'ad_user_data',
|
|
1284
|
+
'ad_personalization'
|
|
1285
|
+
],
|
|
1286
|
+
experience: [
|
|
1287
|
+
'personalization_storage'
|
|
1288
|
+
]
|
|
1289
|
+
};
|
|
1290
|
+
function mapConsentStateToGTM(consentState) {
|
|
1291
|
+
const gtmConfig = {
|
|
1292
|
+
...DEFAULT_GTM_CONSENT_CONFIG
|
|
1293
|
+
};
|
|
1294
|
+
for (const consentType of Object.keys(consentState)){
|
|
1295
|
+
const isGranted = consentState[consentType];
|
|
1296
|
+
const gtmConsentTypes = CONSENT_STATE_TO_GTM_MAPPING[consentType];
|
|
1297
|
+
for (const gtmType of gtmConsentTypes)gtmConfig[gtmType] = isGranted ? 'granted' : 'denied';
|
|
1298
|
+
}
|
|
1299
|
+
return gtmConfig;
|
|
1300
|
+
}
|
|
1301
|
+
function initializeGTMDataLayer(gtm) {
|
|
1302
|
+
const gtmConsent = gtm.consentState ? mapConsentStateToGTM(gtm.consentState) : DEFAULT_GTM_CONSENT_CONFIG;
|
|
1303
|
+
const gtmSetupScript = document.createElement("script");
|
|
1304
|
+
gtmSetupScript.textContent = `
|
|
1305
|
+
window.dataLayer = window.dataLayer || [];
|
|
1306
|
+
window.gtag = function gtag() {
|
|
1307
|
+
window.dataLayer.push(arguments);
|
|
1308
|
+
};
|
|
1309
|
+
window.gtag('consent', 'default', {
|
|
1310
|
+
...${JSON.stringify(gtmConsent)},
|
|
1311
|
+
});
|
|
1312
|
+
window.dataLayer.push({
|
|
1313
|
+
'gtm.start': Date.now(),
|
|
1314
|
+
event: 'gtm.js',
|
|
1315
|
+
});
|
|
1316
|
+
`;
|
|
1317
|
+
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
1318
|
+
document.head.appendChild(gtmSetupScript);
|
|
1319
|
+
}
|
|
1320
|
+
function createGTMScript(gtm) {
|
|
1321
|
+
const gtmScript = document.createElement("script");
|
|
1322
|
+
gtmScript.async = true;
|
|
1323
|
+
gtmScript.src = gtm.customScriptUrl ? gtm.customScriptUrl : `https://www.googletagmanager.com/gtm.js?id=${gtm.id}`;
|
|
1324
|
+
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
1325
|
+
document.head.appendChild(gtmScript);
|
|
1326
|
+
}
|
|
1327
|
+
function setupGTM(gtm) {
|
|
1328
|
+
const id = gtm.id;
|
|
1329
|
+
if (!id || 0 === id.trim().length) throw new Error('GTM container ID is required and must be a non-empty string');
|
|
1330
|
+
if ('undefined' == typeof window || 'undefined' == typeof document) return;
|
|
1331
|
+
initializeGTMDataLayer(gtm);
|
|
1332
|
+
createGTMScript(gtm);
|
|
1333
|
+
}
|
|
1334
|
+
function updateGTMConsent(consentState) {
|
|
1335
|
+
if (!window.gtag) return;
|
|
1336
|
+
window.gtag('consent', 'update', mapConsentStateToGTM(consentState));
|
|
1337
|
+
}
|
|
1262
1338
|
const STORAGE_KEY = 'privacy-consent-storage';
|
|
1263
1339
|
const getStoredConsent = ()=>{
|
|
1264
1340
|
if ('undefined' == typeof window) return null;
|
|
@@ -1311,6 +1387,7 @@ const createConsentManagerStore = (manager, options = {})=>{
|
|
|
1311
1387
|
[name]: value
|
|
1312
1388
|
};
|
|
1313
1389
|
trackingBlocker?.updateConsents(newConsents);
|
|
1390
|
+
updateGTMConsent(newConsents);
|
|
1314
1391
|
return {
|
|
1315
1392
|
consents: newConsents
|
|
1316
1393
|
};
|
|
@@ -1349,6 +1426,7 @@ const createConsentManagerStore = (manager, options = {})=>{
|
|
|
1349
1426
|
consentInfo
|
|
1350
1427
|
});
|
|
1351
1428
|
trackingBlocker?.updateConsents(newConsents);
|
|
1429
|
+
updateGTMConsent(newConsents);
|
|
1352
1430
|
try {
|
|
1353
1431
|
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
|
1354
1432
|
consents: newConsents,
|
|
@@ -1447,6 +1525,14 @@ const createConsentManagerStore = (manager, options = {})=>{
|
|
|
1447
1525
|
}));
|
|
1448
1526
|
if ('undefined' != typeof window) {
|
|
1449
1527
|
window[namespace] = store;
|
|
1528
|
+
if (options.unstable_googleTagManager) try {
|
|
1529
|
+
setupGTM({
|
|
1530
|
+
...options.unstable_googleTagManager,
|
|
1531
|
+
consentState: store.getState().consents
|
|
1532
|
+
});
|
|
1533
|
+
} catch (e) {
|
|
1534
|
+
console.error('Failed to setup Google Tag Manager:', e);
|
|
1535
|
+
}
|
|
1450
1536
|
if (!getStoredConsent()) store.getState().fetchConsentBannerInfo();
|
|
1451
1537
|
}
|
|
1452
1538
|
return store;
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
export type { ComplianceRegion, ComplianceSettings, ConsentBannerResponse, ConsentState, HasConsentedProps, JurisdictionInfo, LocationInfo, NamespaceProps, PrivacySettings, } from './types/compliance';
|
|
37
|
+
export type { GTMConfiguration } from './libs/gtm';
|
|
37
38
|
/**
|
|
38
39
|
* @module
|
|
39
40
|
* API Endpoints
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,YAAY,EACX,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,GACf,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAM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,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1219,6 +1219,82 @@ const initialState = {
|
|
|
1219
1219
|
hasConsented: ()=>false,
|
|
1220
1220
|
setTranslationConfig: ()=>{}
|
|
1221
1221
|
};
|
|
1222
|
+
const DEFAULT_GTM_CONSENT_CONFIG = {
|
|
1223
|
+
functionality_storage: 'denied',
|
|
1224
|
+
security_storage: 'denied',
|
|
1225
|
+
analytics_storage: 'denied',
|
|
1226
|
+
ad_storage: 'denied',
|
|
1227
|
+
ad_user_data: 'denied',
|
|
1228
|
+
ad_personalization: 'denied',
|
|
1229
|
+
personalization_storage: 'denied'
|
|
1230
|
+
};
|
|
1231
|
+
const CONSENT_STATE_TO_GTM_MAPPING = {
|
|
1232
|
+
necessary: [
|
|
1233
|
+
'security_storage'
|
|
1234
|
+
],
|
|
1235
|
+
functionality: [
|
|
1236
|
+
'functionality_storage'
|
|
1237
|
+
],
|
|
1238
|
+
measurement: [
|
|
1239
|
+
'analytics_storage'
|
|
1240
|
+
],
|
|
1241
|
+
marketing: [
|
|
1242
|
+
'ad_storage',
|
|
1243
|
+
'ad_user_data',
|
|
1244
|
+
'ad_personalization'
|
|
1245
|
+
],
|
|
1246
|
+
experience: [
|
|
1247
|
+
'personalization_storage'
|
|
1248
|
+
]
|
|
1249
|
+
};
|
|
1250
|
+
function mapConsentStateToGTM(consentState) {
|
|
1251
|
+
const gtmConfig = {
|
|
1252
|
+
...DEFAULT_GTM_CONSENT_CONFIG
|
|
1253
|
+
};
|
|
1254
|
+
for (const consentType of Object.keys(consentState)){
|
|
1255
|
+
const isGranted = consentState[consentType];
|
|
1256
|
+
const gtmConsentTypes = CONSENT_STATE_TO_GTM_MAPPING[consentType];
|
|
1257
|
+
for (const gtmType of gtmConsentTypes)gtmConfig[gtmType] = isGranted ? 'granted' : 'denied';
|
|
1258
|
+
}
|
|
1259
|
+
return gtmConfig;
|
|
1260
|
+
}
|
|
1261
|
+
function initializeGTMDataLayer(gtm) {
|
|
1262
|
+
const gtmConsent = gtm.consentState ? mapConsentStateToGTM(gtm.consentState) : DEFAULT_GTM_CONSENT_CONFIG;
|
|
1263
|
+
const gtmSetupScript = document.createElement("script");
|
|
1264
|
+
gtmSetupScript.textContent = `
|
|
1265
|
+
window.dataLayer = window.dataLayer || [];
|
|
1266
|
+
window.gtag = function gtag() {
|
|
1267
|
+
window.dataLayer.push(arguments);
|
|
1268
|
+
};
|
|
1269
|
+
window.gtag('consent', 'default', {
|
|
1270
|
+
...${JSON.stringify(gtmConsent)},
|
|
1271
|
+
});
|
|
1272
|
+
window.dataLayer.push({
|
|
1273
|
+
'gtm.start': Date.now(),
|
|
1274
|
+
event: 'gtm.js',
|
|
1275
|
+
});
|
|
1276
|
+
`;
|
|
1277
|
+
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
1278
|
+
document.head.appendChild(gtmSetupScript);
|
|
1279
|
+
}
|
|
1280
|
+
function createGTMScript(gtm) {
|
|
1281
|
+
const gtmScript = document.createElement("script");
|
|
1282
|
+
gtmScript.async = true;
|
|
1283
|
+
gtmScript.src = gtm.customScriptUrl ? gtm.customScriptUrl : `https://www.googletagmanager.com/gtm.js?id=${gtm.id}`;
|
|
1284
|
+
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
1285
|
+
document.head.appendChild(gtmScript);
|
|
1286
|
+
}
|
|
1287
|
+
function setupGTM(gtm) {
|
|
1288
|
+
const id = gtm.id;
|
|
1289
|
+
if (!id || 0 === id.trim().length) throw new Error('GTM container ID is required and must be a non-empty string');
|
|
1290
|
+
if ('undefined' == typeof window || 'undefined' == typeof document) return;
|
|
1291
|
+
initializeGTMDataLayer(gtm);
|
|
1292
|
+
createGTMScript(gtm);
|
|
1293
|
+
}
|
|
1294
|
+
function updateGTMConsent(consentState) {
|
|
1295
|
+
if (!window.gtag) return;
|
|
1296
|
+
window.gtag('consent', 'update', mapConsentStateToGTM(consentState));
|
|
1297
|
+
}
|
|
1222
1298
|
const STORAGE_KEY = 'privacy-consent-storage';
|
|
1223
1299
|
const getStoredConsent = ()=>{
|
|
1224
1300
|
if ('undefined' == typeof window) return null;
|
|
@@ -1271,6 +1347,7 @@ const createConsentManagerStore = (manager, options = {})=>{
|
|
|
1271
1347
|
[name]: value
|
|
1272
1348
|
};
|
|
1273
1349
|
trackingBlocker?.updateConsents(newConsents);
|
|
1350
|
+
updateGTMConsent(newConsents);
|
|
1274
1351
|
return {
|
|
1275
1352
|
consents: newConsents
|
|
1276
1353
|
};
|
|
@@ -1309,6 +1386,7 @@ const createConsentManagerStore = (manager, options = {})=>{
|
|
|
1309
1386
|
consentInfo
|
|
1310
1387
|
});
|
|
1311
1388
|
trackingBlocker?.updateConsents(newConsents);
|
|
1389
|
+
updateGTMConsent(newConsents);
|
|
1312
1390
|
try {
|
|
1313
1391
|
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
|
1314
1392
|
consents: newConsents,
|
|
@@ -1407,6 +1485,14 @@ const createConsentManagerStore = (manager, options = {})=>{
|
|
|
1407
1485
|
}));
|
|
1408
1486
|
if ('undefined' != typeof window) {
|
|
1409
1487
|
window[namespace] = store;
|
|
1488
|
+
if (options.unstable_googleTagManager) try {
|
|
1489
|
+
setupGTM({
|
|
1490
|
+
...options.unstable_googleTagManager,
|
|
1491
|
+
consentState: store.getState().consents
|
|
1492
|
+
});
|
|
1493
|
+
} catch (e) {
|
|
1494
|
+
console.error('Failed to setup Google Tag Manager:', e);
|
|
1495
|
+
}
|
|
1410
1496
|
if (!getStoredConsent()) store.getState().fetchConsentBannerInfo();
|
|
1411
1497
|
}
|
|
1412
1498
|
return store;
|
|
@@ -13,7 +13,7 @@ type ConsentBannerResponse = ContractsOutputs['consent']['showBanner'];
|
|
|
13
13
|
*/
|
|
14
14
|
interface FetchConsentBannerConfig {
|
|
15
15
|
manager: ConsentManagerInterface;
|
|
16
|
-
initialData?: Promise<ContractsOutputs['consent']['showBanner']>;
|
|
16
|
+
initialData?: Promise<ContractsOutputs['consent']['showBanner'] | undefined>;
|
|
17
17
|
initialTranslationConfig?: Partial<TranslationConfig>;
|
|
18
18
|
get: StoreApi<PrivacyConsentState>['getState'];
|
|
19
19
|
set: StoreApi<PrivacyConsentState>['setState'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-consent-banner.d.ts","sourceRoot":"","sources":["../../src/libs/fetch-consent-banner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACN,KAAK,iBAAiB,EAEtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,KAAK,qBAAqB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;AAEvE;;GAEG;AACH,UAAU,wBAAwB;IACjC,OAAO,EAAE,uBAAuB,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-consent-banner.d.ts","sourceRoot":"","sources":["../../src/libs/fetch-consent-banner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACN,KAAK,iBAAiB,EAEtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,KAAK,qBAAqB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;AAEvE;;GAEG;AACH,UAAU,wBAAwB;IACjC,OAAO,EAAE,uBAAuB,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,CAAC;IAC7E,wBAAwB,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACtD,GAAG,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;IAC/C,GAAG,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;CAC/C;AA8ED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC3C,MAAM,EAAE,wBAAwB,GAC9B,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA0E5C"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ConsentState } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* GTM-specific consent configuration matching Google's consent mode API
|
|
4
|
+
*/
|
|
5
|
+
interface GTMConsentConfiguration {
|
|
6
|
+
ad_storage: 'granted' | 'denied';
|
|
7
|
+
ad_personalization: 'granted' | 'denied';
|
|
8
|
+
ad_user_data: 'granted' | 'denied';
|
|
9
|
+
analytics_storage: 'granted' | 'denied';
|
|
10
|
+
personalization_storage: 'granted' | 'denied';
|
|
11
|
+
functionality_storage: 'granted' | 'denied';
|
|
12
|
+
security_storage: 'granted' | 'denied';
|
|
13
|
+
}
|
|
14
|
+
interface Options {
|
|
15
|
+
/**
|
|
16
|
+
* Your Google Tag Manager container ID. Begins with 'GTM-'.
|
|
17
|
+
*/
|
|
18
|
+
id: string;
|
|
19
|
+
/**
|
|
20
|
+
* Custom URL for your GTM script. Include the 'id' parameter.
|
|
21
|
+
*
|
|
22
|
+
* @default `https://www.googletagmanager.com/gtm.js?id=${id}`
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* https://www.c15t.dev/gtm.js?id=GTM-XXXXXXX
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
customScriptUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The consent state to use for the GTM consent configuration.
|
|
32
|
+
*/
|
|
33
|
+
consentState?: ConsentState;
|
|
34
|
+
}
|
|
35
|
+
export type GTMConfiguration = Omit<Options, 'consentState'>;
|
|
36
|
+
/**
|
|
37
|
+
* Extended Window interface to include GTM-specific properties
|
|
38
|
+
*/
|
|
39
|
+
declare global {
|
|
40
|
+
interface Window {
|
|
41
|
+
dataLayer: unknown[];
|
|
42
|
+
gtag: (...args: unknown[]) => void;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Converts ConsentState to GTM consent configuration
|
|
47
|
+
*
|
|
48
|
+
* @param consentState - The application's consent state
|
|
49
|
+
* @returns GTM-compatible consent configuration
|
|
50
|
+
*
|
|
51
|
+
* @see {@link CONSENT_STATE_TO_GTM_MAPPING} for the mapping logic
|
|
52
|
+
*/
|
|
53
|
+
export declare function mapConsentStateToGTM(consentState: ConsentState): GTMConsentConfiguration;
|
|
54
|
+
/**
|
|
55
|
+
* Initializes the Google Tag Manager dataLayer and consent configuration
|
|
56
|
+
*
|
|
57
|
+
* @param configuration - GTM setup configuration options
|
|
58
|
+
*
|
|
59
|
+
* @throws {Error} When GTM container ID is empty or invalid
|
|
60
|
+
*
|
|
61
|
+
* @internal This function should be called before loading the GTM script
|
|
62
|
+
*/
|
|
63
|
+
export declare function initializeGTMDataLayer(gtm: Options): void;
|
|
64
|
+
/**
|
|
65
|
+
* Creates and injects the Google Tag Manager script into the document head
|
|
66
|
+
*
|
|
67
|
+
* @param gtmContainerId - The GTM container ID (e.g., 'GTM-XXXXXXX')
|
|
68
|
+
*
|
|
69
|
+
* @throws {Error} When script injection fails
|
|
70
|
+
*
|
|
71
|
+
* @see {@link initializeGTMDataLayer} - Should be called before this function
|
|
72
|
+
*/
|
|
73
|
+
export declare function createGTMScript(gtm: Options): void;
|
|
74
|
+
/**
|
|
75
|
+
* Complete Google Tag Manager setup including dataLayer initialization and script injection
|
|
76
|
+
*
|
|
77
|
+
* @param configuration - Complete GTM configuration options
|
|
78
|
+
*
|
|
79
|
+
* @throws {Error} When GTM container ID is empty or invalid
|
|
80
|
+
* @throws {Error} When script injection fails
|
|
81
|
+
*
|
|
82
|
+
* @see {@link initializeGTMDataLayer} - For dataLayer setup only
|
|
83
|
+
* @see {@link createGTMScript} - For script injection only
|
|
84
|
+
*/
|
|
85
|
+
export declare function setupGTM(gtm: Options): void;
|
|
86
|
+
/**
|
|
87
|
+
* Updates the Google Tag Manager consent configuration
|
|
88
|
+
*
|
|
89
|
+
* @param consentState - The consent state to update
|
|
90
|
+
*/
|
|
91
|
+
export declare function updateGTMConsent(consentState: ConsentState): void;
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=gtm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtm.d.ts","sourceRoot":"","sources":["../../src/libs/gtm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,UAAU,uBAAuB;IAChC,UAAU,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjC,kBAAkB,EAAE,SAAS,GAAG,QAAQ,CAAC;IACzC,YAAY,EAAE,SAAS,GAAG,QAAQ,CAAC;IACnC,iBAAiB,EAAE,SAAS,GAAG,QAAQ,CAAC;IACxC,uBAAuB,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC9C,qBAAqB,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5C,gBAAgB,EAAE,SAAS,GAAG,QAAQ,CAAC;CACvC;AAED,UAAU,OAAO;IAChB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAE7D;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,SAAS,EAAE,OAAO,EAAE,CAAC;QACrB,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;KACnC;CACD;AA0BD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,YAAY,EAAE,YAAY,GACxB,uBAAuB,CAczB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,QA0BlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,QAY3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAe3C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAMjE"}
|
package/dist/store.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { PrivacyConsentState } from './store.type';
|
|
|
10
10
|
import type { ComplianceSettings } from './types/compliance';
|
|
11
11
|
import { type AllConsentNames } from './types/gdpr';
|
|
12
12
|
import type { ContractsOutputs } from '@c15t/backend/contracts';
|
|
13
|
+
import { type GTMConfiguration } from './libs/gtm';
|
|
13
14
|
/**
|
|
14
15
|
* Configuration options for the consent manager store.
|
|
15
16
|
*
|
|
@@ -42,6 +43,10 @@ export interface StoreOptions {
|
|
|
42
43
|
* @default false
|
|
43
44
|
*/
|
|
44
45
|
isConsentDomain?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Google Tag Manager configuration.
|
|
48
|
+
*/
|
|
49
|
+
unstable_googleTagManager?: GTMConfiguration;
|
|
45
50
|
/**
|
|
46
51
|
* Initial Translation Config
|
|
47
52
|
*/
|
|
@@ -54,7 +59,7 @@ export interface StoreOptions {
|
|
|
54
59
|
* Initial showConsentBanner value. This will set a cookie for the consent banner.
|
|
55
60
|
* @internal
|
|
56
61
|
*/
|
|
57
|
-
_initialData?: Promise<ContractsOutputs['consent']['showBanner']>;
|
|
62
|
+
_initialData?: Promise<ContractsOutputs['consent']['showBanner'] | undefined>;
|
|
58
63
|
}
|
|
59
64
|
export interface StoreConfig extends Pick<StoreOptions, 'trackingBlockerConfig'> {
|
|
60
65
|
}
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAQvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EACX,kBAAkB,EAGlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,eAAe,EAAgB,MAAM,cAAc,CAAC;AAElE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAQvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,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