@mparticle/web-google-tag-manager-kit 2.1.1 → 2.2.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.
|
@@ -50,12 +50,6 @@ ConsentHandler.prototype.getUserConsentState = function () {
|
|
|
50
50
|
return userConsentState;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
ConsentHandler.prototype.getEventConsentState = function (eventConsentState) {
|
|
54
|
-
return eventConsentState && eventConsentState.getGDPRConsentState
|
|
55
|
-
? eventConsentState.getGDPRConsentState()
|
|
56
|
-
: {};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
53
|
ConsentHandler.prototype.getConsentSettings = function () {
|
|
60
54
|
var consentSettings = {};
|
|
61
55
|
|
|
@@ -251,6 +245,44 @@ Common.prototype.sendConsent = function (type, payload) {
|
|
|
251
245
|
customDataLayer('consent', type, payload);
|
|
252
246
|
};
|
|
253
247
|
|
|
248
|
+
Common.prototype.getEventConsentState = function (eventConsentState) {
|
|
249
|
+
return eventConsentState && eventConsentState.getGDPRConsentState
|
|
250
|
+
? eventConsentState.getGDPRConsentState()
|
|
251
|
+
: {};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
|
|
255
|
+
// If consent payload is empty,
|
|
256
|
+
// we never sent an initial default consent state
|
|
257
|
+
// so we shouldn't send an update.
|
|
258
|
+
if (
|
|
259
|
+
this.consentPayloadAsString &&
|
|
260
|
+
this.consentMappings &&
|
|
261
|
+
!this.isEmpty(consentState)
|
|
262
|
+
) {
|
|
263
|
+
var updatedConsentPayload =
|
|
264
|
+
this.consentHandler.generateConsentStatePayloadFromMappings(
|
|
265
|
+
consentState,
|
|
266
|
+
this.consentMappings
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
270
|
+
|
|
271
|
+
if (eventConsentAsString !== this.consentPayloadAsString) {
|
|
272
|
+
this.sendConsent('update', updatedConsentPayload);
|
|
273
|
+
this.consentPayloadAsString = eventConsentAsString;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
Common.prototype.sendDefaultConsentPayloadToGoogle = function (consentPayload) {
|
|
279
|
+
this.consentPayloadAsString = JSON.stringify(
|
|
280
|
+
consentPayload
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
this.sendConsent('default', consentPayload);
|
|
284
|
+
};
|
|
285
|
+
|
|
254
286
|
Common.prototype.cloneObject = function (obj) {
|
|
255
287
|
return JSON.parse(JSON.stringify(obj));
|
|
256
288
|
};
|
|
@@ -576,34 +608,11 @@ function EventHandler(common) {
|
|
|
576
608
|
this.common = common || {};
|
|
577
609
|
}
|
|
578
610
|
|
|
579
|
-
EventHandler.prototype.maybeSendConsentUpdateToGoogle = function (event) {
|
|
580
|
-
// If consent payload is empty,
|
|
581
|
-
// we never sent an initial default consent state
|
|
582
|
-
// so we shouldn't send an update.
|
|
583
|
-
if (this.common.consentPayloadAsString && this.common.consentMappings) {
|
|
584
|
-
var eventConsentState = this.common.consentHandler.getEventConsentState(
|
|
585
|
-
event.ConsentState
|
|
586
|
-
);
|
|
587
|
-
|
|
588
|
-
if (!this.common.isEmpty(eventConsentState)) {
|
|
589
|
-
var updatedConsentPayload =
|
|
590
|
-
this.common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
591
|
-
eventConsentState,
|
|
592
|
-
this.common.consentMappings
|
|
593
|
-
);
|
|
594
|
-
|
|
595
|
-
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
596
|
-
|
|
597
|
-
if (eventConsentAsString !== this.common.consentPayloadAsString) {
|
|
598
|
-
this.common.sendConsent('update', updatedConsentPayload);
|
|
599
|
-
this.common.consentPayloadAsString = eventConsentAsString;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
|
|
605
611
|
EventHandler.prototype.logEvent = function (event) {
|
|
606
|
-
this.
|
|
612
|
+
var eventConsentState = this.common.getEventConsentState(
|
|
613
|
+
event.ConsentState
|
|
614
|
+
);
|
|
615
|
+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
|
|
607
616
|
this.common.send({
|
|
608
617
|
event: event,
|
|
609
618
|
});
|
|
@@ -614,7 +623,10 @@ EventHandler.prototype.logEvent = function (event) {
|
|
|
614
623
|
EventHandler.prototype.logError = function() {};
|
|
615
624
|
|
|
616
625
|
EventHandler.prototype.logPageView = function (event) {
|
|
617
|
-
this.
|
|
626
|
+
var eventConsentState = this.common.getEventConsentState(
|
|
627
|
+
event.ConsentState
|
|
628
|
+
);
|
|
629
|
+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
|
|
618
630
|
this.common.send({
|
|
619
631
|
event: event,
|
|
620
632
|
eventType: 'screen_view'
|
|
@@ -779,31 +791,41 @@ var initialization = {
|
|
|
779
791
|
isInitialized = initializeContainer(
|
|
780
792
|
containerId,
|
|
781
793
|
common.customDataLayerName,
|
|
782
|
-
previewUrl
|
|
794
|
+
previewUrl,
|
|
795
|
+
common.settings.preventAutoBlock
|
|
783
796
|
);
|
|
784
797
|
}
|
|
785
798
|
|
|
786
799
|
common.consentPayloadDefaults =
|
|
787
800
|
common.consentHandler.getConsentSettings();
|
|
788
|
-
var initialConsentState = common.consentHandler.getUserConsentState();
|
|
789
801
|
|
|
790
|
-
var defaultConsentPayload =
|
|
802
|
+
var defaultConsentPayload = common.cloneObject(common.consentPayloadDefaults);
|
|
803
|
+
var updatedConsentState = common.consentHandler.getUserConsentState();
|
|
804
|
+
var updatedDefaultConsentPayload =
|
|
791
805
|
common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
792
|
-
|
|
806
|
+
updatedConsentState,
|
|
793
807
|
common.consentMappings
|
|
794
808
|
);
|
|
795
809
|
|
|
810
|
+
// If a default consent payload exists (as selected in the mParticle UI), set it as the default
|
|
796
811
|
if (!common.isEmpty(defaultConsentPayload)) {
|
|
797
|
-
common.
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
common.
|
|
812
|
+
common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
|
|
813
|
+
// If a default consent payload does not exist, but the user currently has updated their consent,
|
|
814
|
+
// send that as the default because a default must be sent
|
|
815
|
+
} else if (!common.isEmpty(updatedDefaultConsentPayload)) {
|
|
816
|
+
common.sendDefaultConsentPayloadToGoogle(updatedDefaultConsentPayload);
|
|
802
817
|
}
|
|
818
|
+
|
|
819
|
+
common.maybeSendConsentUpdateToGoogle(updatedConsentState);
|
|
803
820
|
},
|
|
804
821
|
};
|
|
805
822
|
|
|
806
|
-
function initializeContainer(
|
|
823
|
+
function initializeContainer(
|
|
824
|
+
containerId,
|
|
825
|
+
dataLayerName,
|
|
826
|
+
previewUrl,
|
|
827
|
+
preventAutoBlock
|
|
828
|
+
) {
|
|
807
829
|
var url = 'https://www.googletagmanager.com/gtm.js';
|
|
808
830
|
|
|
809
831
|
// If Settings contains previewUrl, we should tack that onto the gtm snippet
|
|
@@ -818,21 +840,27 @@ function initializeContainer(containerId, dataLayerName, previewUrl) {
|
|
|
818
840
|
|
|
819
841
|
url += '&l=' + dataLayerName;
|
|
820
842
|
|
|
821
|
-
loadSnippet(url, dataLayerName);
|
|
843
|
+
loadSnippet(url, dataLayerName, preventAutoBlock);
|
|
822
844
|
|
|
823
845
|
return true;
|
|
824
846
|
}
|
|
825
847
|
|
|
826
|
-
function loadSnippet(url, dataLayerName) {
|
|
848
|
+
function loadSnippet(url, dataLayerName, preventAutoBlock) {
|
|
827
849
|
window[dataLayerName].push({
|
|
828
850
|
'gtm.start': new Date().getTime(),
|
|
829
|
-
event: 'gtm.js'
|
|
851
|
+
event: 'gtm.js',
|
|
830
852
|
});
|
|
831
853
|
|
|
832
854
|
var gTagScript = document.createElement('script');
|
|
833
855
|
gTagScript.type = 'text/javascript';
|
|
834
856
|
gTagScript.async = true;
|
|
835
857
|
gTagScript.src = url;
|
|
858
|
+
if (preventAutoBlock === 'True') {
|
|
859
|
+
gTagScript.setAttributeNode(
|
|
860
|
+
window.document.createAttribute('data-ot-ignore')
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
|
|
836
864
|
(
|
|
837
865
|
document.getElementsByTagName('head')[0] ||
|
|
838
866
|
document.getElementsByTagName('body')[0]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-google-tag-manager-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-google-tag-manager",
|
|
5
5
|
"main": "dist/GoogleTagManager-Kit.common.js",
|
|
6
6
|
"browser": "dist/GoogleTagManager-Kit.common.js",
|