Skip to content

Commit 5a89bd7

Browse files
committed
feat: Support setting for OneTrust auto-block prevention
1 parent 14a4efd commit 5a89bd7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/initialization.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ var initialization = {
6363
isInitialized = initializeContainer(
6464
containerId,
6565
common.customDataLayerName,
66-
previewUrl
66+
previewUrl,
67+
common.settings
6768
);
6869
}
6970

@@ -88,11 +89,10 @@ var initialization = {
8889
}
8990

9091
common.maybeSendConsentUpdateToGoogle(updatedConsentState);
91-
9292
},
9393
};
9494

95-
function initializeContainer(containerId, dataLayerName, previewUrl) {
95+
function initializeContainer(containerId, dataLayerName, previewUrl, settings) {
9696
var url = 'https://www.googletagmanager.com/gtm.js';
9797

9898
// If Settings contains previewUrl, we should tack that onto the gtm snippet
@@ -107,21 +107,27 @@ function initializeContainer(containerId, dataLayerName, previewUrl) {
107107

108108
url += '&l=' + dataLayerName;
109109

110-
loadSnippet(url, dataLayerName);
110+
loadSnippet(url, dataLayerName, settings);
111111

112112
return true;
113113
}
114114

115-
function loadSnippet(url, dataLayerName) {
115+
function loadSnippet(url, dataLayerName, settings) {
116116
window[dataLayerName].push({
117117
'gtm.start': new Date().getTime(),
118-
event: 'gtm.js'
118+
event: 'gtm.js',
119119
});
120120

121121
var gTagScript = document.createElement('script');
122122
gTagScript.type = 'text/javascript';
123123
gTagScript.async = true;
124124
gTagScript.src = url;
125+
if (settings.preventAutoBlock === 'True') {
126+
gTagScript.setAttributeNode(
127+
window.document.createAttribute('data-ot-ignore')
128+
);
129+
}
130+
125131
(
126132
document.getElementsByTagName('head')[0] ||
127133
document.getElementsByTagName('body')[0]

0 commit comments

Comments
 (0)