Skip to content

Commit

Permalink
feat: Support setting for OneTrust auto-block prevention (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 authored Sep 26, 2024
1 parent 14a4efd commit 687fcd2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ var initialization = {
isInitialized = initializeContainer(
containerId,
common.customDataLayerName,
previewUrl
previewUrl,
common.settings.preventAutoBlock
);
}

Expand All @@ -88,11 +89,15 @@ var initialization = {
}

common.maybeSendConsentUpdateToGoogle(updatedConsentState);

},
};

function initializeContainer(containerId, dataLayerName, previewUrl) {
function initializeContainer(
containerId,
dataLayerName,
previewUrl,
preventAutoBlock
) {
var url = 'https://www.googletagmanager.com/gtm.js';

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

url += '&l=' + dataLayerName;

loadSnippet(url, dataLayerName);
loadSnippet(url, dataLayerName, preventAutoBlock);

return true;
}

function loadSnippet(url, dataLayerName) {
function loadSnippet(url, dataLayerName, preventAutoBlock) {
window[dataLayerName].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
event: 'gtm.js',
});

var gTagScript = document.createElement('script');
gTagScript.type = 'text/javascript';
gTagScript.async = true;
gTagScript.src = url;
if (preventAutoBlock === 'True') {
gTagScript.setAttributeNode(
window.document.createAttribute('data-ot-ignore')
);
}

(
document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]
Expand Down

0 comments on commit 687fcd2

Please sign in to comment.