@blotoutio/providers-google-ads-clicks-sdk 0.72.0 → 1.0.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/index.cjs.js +45 -16
- package/index.js +45 -16
- package/index.mjs +45 -16
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
const packageName = 'googleAdsClicks';
|
|
4
4
|
|
|
5
|
+
const isBool = (v) => typeof v == 'boolean';
|
|
6
|
+
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
|
|
7
|
+
/**
|
|
8
|
+
* This function validates user consent for a given provider type, not based on tagName.
|
|
9
|
+
*/
|
|
10
|
+
const hasUserConsentForProvider = (consent, provider) => {
|
|
11
|
+
if (!isRecord(consent)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
15
|
+
if (provider in consent) {
|
|
16
|
+
const providerSpecific = consent[provider];
|
|
17
|
+
if (isBool(providerSpecific)) {
|
|
18
|
+
allowed = providerSpecific;
|
|
19
|
+
}
|
|
20
|
+
else if (isRecord(providerSpecific)) {
|
|
21
|
+
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return allowed;
|
|
25
|
+
};
|
|
26
|
+
|
|
5
27
|
const upsert = (map, key, update, createDefault) => {
|
|
6
28
|
const currentValue = map.has(key)
|
|
7
29
|
? map.get(key)
|
|
@@ -303,7 +325,20 @@ const isoCountries = new Map([
|
|
|
303
325
|
new Set(isoCountries.keys());
|
|
304
326
|
|
|
305
327
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
306
|
-
|
|
328
|
+
// TODO: once categories becomes a stable field, we need to remove this and start using categories data for google consent mode.
|
|
329
|
+
const getGoogleConsentFromChannels = (consent) => {
|
|
330
|
+
const gadsConsent = hasUserConsentForProvider(consent, 'googleAdsClicks');
|
|
331
|
+
const ga4Consent = hasUserConsentForProvider(consent, 'googleAnalytics4');
|
|
332
|
+
return {
|
|
333
|
+
analytics_storage: ga4Consent ? 'granted' : 'denied',
|
|
334
|
+
ad_storage: gadsConsent ? 'granted' : 'denied',
|
|
335
|
+
ad_user_data: gadsConsent ? 'granted' : 'denied',
|
|
336
|
+
ad_personalization: gadsConsent ? 'granted' : 'denied',
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
341
|
+
const initGAds = (ID, consent, executionContext) => {
|
|
307
342
|
var _a;
|
|
308
343
|
window.dataLayer = window.dataLayer || [];
|
|
309
344
|
window.gtag = function gtag() {
|
|
@@ -317,18 +352,13 @@ const initGAds = (ID, executionContext) => {
|
|
|
317
352
|
break;
|
|
318
353
|
}
|
|
319
354
|
}
|
|
355
|
+
const data = getGoogleConsentFromChannels(consent);
|
|
320
356
|
if (isConsentInitialised) {
|
|
321
|
-
window.gtag('consent', 'update',
|
|
322
|
-
ad_storage: 'granted',
|
|
323
|
-
ad_user_data: 'granted',
|
|
324
|
-
ad_personalization: 'granted',
|
|
325
|
-
});
|
|
357
|
+
window.gtag('consent', 'update', data);
|
|
326
358
|
}
|
|
327
359
|
else {
|
|
328
360
|
window.gtag('consent', 'default', {
|
|
329
|
-
|
|
330
|
-
ad_user_data: 'granted',
|
|
331
|
-
ad_personalization: 'granted',
|
|
361
|
+
...data,
|
|
332
362
|
functional_storage: 'granted',
|
|
333
363
|
personalization_storage: 'granted',
|
|
334
364
|
security_storage: 'granted',
|
|
@@ -346,7 +376,7 @@ const initGAds = (ID, executionContext) => {
|
|
|
346
376
|
script.parentNode.insertBefore(element, script);
|
|
347
377
|
}
|
|
348
378
|
};
|
|
349
|
-
const init = ({ manifest, executionContext }) => {
|
|
379
|
+
const init = ({ manifest, consentData, executionContext }) => {
|
|
350
380
|
var _a, _b;
|
|
351
381
|
if (!window || !((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['tagId'])) {
|
|
352
382
|
return;
|
|
@@ -359,7 +389,7 @@ const init = ({ manifest, executionContext }) => {
|
|
|
359
389
|
}
|
|
360
390
|
if (!window.google_tag_manager ||
|
|
361
391
|
!window.google_tag_manager[manifest.variables['tagId']]) {
|
|
362
|
-
initGAds(manifest.variables['tagId'], executionContext);
|
|
392
|
+
initGAds(manifest.variables['tagId'], consentData.consent, executionContext);
|
|
363
393
|
}
|
|
364
394
|
if (window.gtag) {
|
|
365
395
|
window.gtag('config', manifest.variables['tagId'], customConfig);
|
|
@@ -534,18 +564,17 @@ const tag = ({ data, eventName, manifestVariables, eventId, destination, }) => {
|
|
|
534
564
|
}
|
|
535
565
|
return {
|
|
536
566
|
loaded: isLoaded,
|
|
537
|
-
sdkVersion: "0.
|
|
567
|
+
sdkVersion: "1.0.0" ,
|
|
538
568
|
};
|
|
539
569
|
};
|
|
540
570
|
|
|
541
|
-
const consent = ({
|
|
571
|
+
const consent = ({ consentData }) => {
|
|
542
572
|
if (!(window === null || window === void 0 ? void 0 : window.gtag)) {
|
|
543
573
|
return;
|
|
544
574
|
}
|
|
575
|
+
const data = getGoogleConsentFromChannels(consentData.consent);
|
|
545
576
|
window.gtag('consent', 'update', {
|
|
546
|
-
|
|
547
|
-
ad_user_data: hasConsent ? 'granted' : 'denied',
|
|
548
|
-
ad_personalization: hasConsent ? 'granted' : 'denied',
|
|
577
|
+
...data,
|
|
549
578
|
personalization_storage: 'granted',
|
|
550
579
|
security_storage: 'granted',
|
|
551
580
|
functional_storage: 'granted',
|
package/index.js
CHANGED
|
@@ -3,6 +3,28 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
3
3
|
|
|
4
4
|
const packageName = 'googleAdsClicks';
|
|
5
5
|
|
|
6
|
+
const isBool = (v) => typeof v == 'boolean';
|
|
7
|
+
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
|
|
8
|
+
/**
|
|
9
|
+
* This function validates user consent for a given provider type, not based on tagName.
|
|
10
|
+
*/
|
|
11
|
+
const hasUserConsentForProvider = (consent, provider) => {
|
|
12
|
+
if (!isRecord(consent)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
16
|
+
if (provider in consent) {
|
|
17
|
+
const providerSpecific = consent[provider];
|
|
18
|
+
if (isBool(providerSpecific)) {
|
|
19
|
+
allowed = providerSpecific;
|
|
20
|
+
}
|
|
21
|
+
else if (isRecord(providerSpecific)) {
|
|
22
|
+
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return allowed;
|
|
26
|
+
};
|
|
27
|
+
|
|
6
28
|
const upsert = (map, key, update, createDefault) => {
|
|
7
29
|
const currentValue = map.has(key)
|
|
8
30
|
? map.get(key)
|
|
@@ -304,7 +326,20 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
304
326
|
new Set(isoCountries.keys());
|
|
305
327
|
|
|
306
328
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
307
|
-
|
|
329
|
+
// TODO: once categories becomes a stable field, we need to remove this and start using categories data for google consent mode.
|
|
330
|
+
const getGoogleConsentFromChannels = (consent) => {
|
|
331
|
+
const gadsConsent = hasUserConsentForProvider(consent, 'googleAdsClicks');
|
|
332
|
+
const ga4Consent = hasUserConsentForProvider(consent, 'googleAnalytics4');
|
|
333
|
+
return {
|
|
334
|
+
analytics_storage: ga4Consent ? 'granted' : 'denied',
|
|
335
|
+
ad_storage: gadsConsent ? 'granted' : 'denied',
|
|
336
|
+
ad_user_data: gadsConsent ? 'granted' : 'denied',
|
|
337
|
+
ad_personalization: gadsConsent ? 'granted' : 'denied',
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
342
|
+
const initGAds = (ID, consent, executionContext) => {
|
|
308
343
|
var _a;
|
|
309
344
|
window.dataLayer = window.dataLayer || [];
|
|
310
345
|
window.gtag = function gtag() {
|
|
@@ -318,18 +353,13 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
318
353
|
break;
|
|
319
354
|
}
|
|
320
355
|
}
|
|
356
|
+
const data = getGoogleConsentFromChannels(consent);
|
|
321
357
|
if (isConsentInitialised) {
|
|
322
|
-
window.gtag('consent', 'update',
|
|
323
|
-
ad_storage: 'granted',
|
|
324
|
-
ad_user_data: 'granted',
|
|
325
|
-
ad_personalization: 'granted',
|
|
326
|
-
});
|
|
358
|
+
window.gtag('consent', 'update', data);
|
|
327
359
|
}
|
|
328
360
|
else {
|
|
329
361
|
window.gtag('consent', 'default', {
|
|
330
|
-
|
|
331
|
-
ad_user_data: 'granted',
|
|
332
|
-
ad_personalization: 'granted',
|
|
362
|
+
...data,
|
|
333
363
|
functional_storage: 'granted',
|
|
334
364
|
personalization_storage: 'granted',
|
|
335
365
|
security_storage: 'granted',
|
|
@@ -347,7 +377,7 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
347
377
|
script.parentNode.insertBefore(element, script);
|
|
348
378
|
}
|
|
349
379
|
};
|
|
350
|
-
const init = ({ manifest, executionContext }) => {
|
|
380
|
+
const init = ({ manifest, consentData, executionContext }) => {
|
|
351
381
|
var _a, _b;
|
|
352
382
|
if (!window || !((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['tagId'])) {
|
|
353
383
|
return;
|
|
@@ -360,7 +390,7 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
360
390
|
}
|
|
361
391
|
if (!window.google_tag_manager ||
|
|
362
392
|
!window.google_tag_manager[manifest.variables['tagId']]) {
|
|
363
|
-
initGAds(manifest.variables['tagId'], executionContext);
|
|
393
|
+
initGAds(manifest.variables['tagId'], consentData.consent, executionContext);
|
|
364
394
|
}
|
|
365
395
|
if (window.gtag) {
|
|
366
396
|
window.gtag('config', manifest.variables['tagId'], customConfig);
|
|
@@ -535,18 +565,17 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
535
565
|
}
|
|
536
566
|
return {
|
|
537
567
|
loaded: isLoaded,
|
|
538
|
-
sdkVersion: "0.
|
|
568
|
+
sdkVersion: "1.0.0" ,
|
|
539
569
|
};
|
|
540
570
|
};
|
|
541
571
|
|
|
542
|
-
const consent = ({
|
|
572
|
+
const consent = ({ consentData }) => {
|
|
543
573
|
if (!(window === null || window === void 0 ? void 0 : window.gtag)) {
|
|
544
574
|
return;
|
|
545
575
|
}
|
|
576
|
+
const data = getGoogleConsentFromChannels(consentData.consent);
|
|
546
577
|
window.gtag('consent', 'update', {
|
|
547
|
-
|
|
548
|
-
ad_user_data: hasConsent ? 'granted' : 'denied',
|
|
549
|
-
ad_personalization: hasConsent ? 'granted' : 'denied',
|
|
578
|
+
...data,
|
|
550
579
|
personalization_storage: 'granted',
|
|
551
580
|
security_storage: 'granted',
|
|
552
581
|
functional_storage: 'granted',
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
const packageName = 'googleAdsClicks';
|
|
2
2
|
|
|
3
|
+
const isBool = (v) => typeof v == 'boolean';
|
|
4
|
+
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
|
|
5
|
+
/**
|
|
6
|
+
* This function validates user consent for a given provider type, not based on tagName.
|
|
7
|
+
*/
|
|
8
|
+
const hasUserConsentForProvider = (consent, provider) => {
|
|
9
|
+
if (!isRecord(consent)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
13
|
+
if (provider in consent) {
|
|
14
|
+
const providerSpecific = consent[provider];
|
|
15
|
+
if (isBool(providerSpecific)) {
|
|
16
|
+
allowed = providerSpecific;
|
|
17
|
+
}
|
|
18
|
+
else if (isRecord(providerSpecific)) {
|
|
19
|
+
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return allowed;
|
|
23
|
+
};
|
|
24
|
+
|
|
3
25
|
const upsert = (map, key, update, createDefault) => {
|
|
4
26
|
const currentValue = map.has(key)
|
|
5
27
|
? map.get(key)
|
|
@@ -301,7 +323,20 @@ const isoCountries = new Map([
|
|
|
301
323
|
new Set(isoCountries.keys());
|
|
302
324
|
|
|
303
325
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
304
|
-
|
|
326
|
+
// TODO: once categories becomes a stable field, we need to remove this and start using categories data for google consent mode.
|
|
327
|
+
const getGoogleConsentFromChannels = (consent) => {
|
|
328
|
+
const gadsConsent = hasUserConsentForProvider(consent, 'googleAdsClicks');
|
|
329
|
+
const ga4Consent = hasUserConsentForProvider(consent, 'googleAnalytics4');
|
|
330
|
+
return {
|
|
331
|
+
analytics_storage: ga4Consent ? 'granted' : 'denied',
|
|
332
|
+
ad_storage: gadsConsent ? 'granted' : 'denied',
|
|
333
|
+
ad_user_data: gadsConsent ? 'granted' : 'denied',
|
|
334
|
+
ad_personalization: gadsConsent ? 'granted' : 'denied',
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
339
|
+
const initGAds = (ID, consent, executionContext) => {
|
|
305
340
|
var _a;
|
|
306
341
|
window.dataLayer = window.dataLayer || [];
|
|
307
342
|
window.gtag = function gtag() {
|
|
@@ -315,18 +350,13 @@ const initGAds = (ID, executionContext) => {
|
|
|
315
350
|
break;
|
|
316
351
|
}
|
|
317
352
|
}
|
|
353
|
+
const data = getGoogleConsentFromChannels(consent);
|
|
318
354
|
if (isConsentInitialised) {
|
|
319
|
-
window.gtag('consent', 'update',
|
|
320
|
-
ad_storage: 'granted',
|
|
321
|
-
ad_user_data: 'granted',
|
|
322
|
-
ad_personalization: 'granted',
|
|
323
|
-
});
|
|
355
|
+
window.gtag('consent', 'update', data);
|
|
324
356
|
}
|
|
325
357
|
else {
|
|
326
358
|
window.gtag('consent', 'default', {
|
|
327
|
-
|
|
328
|
-
ad_user_data: 'granted',
|
|
329
|
-
ad_personalization: 'granted',
|
|
359
|
+
...data,
|
|
330
360
|
functional_storage: 'granted',
|
|
331
361
|
personalization_storage: 'granted',
|
|
332
362
|
security_storage: 'granted',
|
|
@@ -344,7 +374,7 @@ const initGAds = (ID, executionContext) => {
|
|
|
344
374
|
script.parentNode.insertBefore(element, script);
|
|
345
375
|
}
|
|
346
376
|
};
|
|
347
|
-
const init = ({ manifest, executionContext }) => {
|
|
377
|
+
const init = ({ manifest, consentData, executionContext }) => {
|
|
348
378
|
var _a, _b;
|
|
349
379
|
if (!window || !((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['tagId'])) {
|
|
350
380
|
return;
|
|
@@ -357,7 +387,7 @@ const init = ({ manifest, executionContext }) => {
|
|
|
357
387
|
}
|
|
358
388
|
if (!window.google_tag_manager ||
|
|
359
389
|
!window.google_tag_manager[manifest.variables['tagId']]) {
|
|
360
|
-
initGAds(manifest.variables['tagId'], executionContext);
|
|
390
|
+
initGAds(manifest.variables['tagId'], consentData.consent, executionContext);
|
|
361
391
|
}
|
|
362
392
|
if (window.gtag) {
|
|
363
393
|
window.gtag('config', manifest.variables['tagId'], customConfig);
|
|
@@ -532,18 +562,17 @@ const tag = ({ data, eventName, manifestVariables, eventId, destination, }) => {
|
|
|
532
562
|
}
|
|
533
563
|
return {
|
|
534
564
|
loaded: isLoaded,
|
|
535
|
-
sdkVersion: "0.
|
|
565
|
+
sdkVersion: "1.0.0" ,
|
|
536
566
|
};
|
|
537
567
|
};
|
|
538
568
|
|
|
539
|
-
const consent = ({
|
|
569
|
+
const consent = ({ consentData }) => {
|
|
540
570
|
if (!(window === null || window === void 0 ? void 0 : window.gtag)) {
|
|
541
571
|
return;
|
|
542
572
|
}
|
|
573
|
+
const data = getGoogleConsentFromChannels(consentData.consent);
|
|
543
574
|
window.gtag('consent', 'update', {
|
|
544
|
-
|
|
545
|
-
ad_user_data: hasConsent ? 'granted' : 'denied',
|
|
546
|
-
ad_personalization: hasConsent ? 'granted' : 'denied',
|
|
575
|
+
...data,
|
|
547
576
|
personalization_storage: 'granted',
|
|
548
577
|
security_storage: 'granted',
|
|
549
578
|
functional_storage: 'granted',
|