Created
May 28, 2019 07:06
-
-
Save nedimdragic/e0bec9ac191170f00d6d1cdb486b9efb to your computer and use it in GitHub Desktop.
Tealium Consent Manager - OneTrust Cookie Consent Manager Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(u){ | |
var addListener = function(element, event, callback) { | |
if(element.addEventListener) { | |
element.addEventListener(event, callback, false); | |
} | |
else if(element.attachEvent) { | |
element.attachEvent('on' + event, callback); | |
} | |
}; | |
var readDataAndSetConsentPref = function(data){ | |
var consGroupNumber, | |
consent = data.detail; | |
utag.gdpr.setAllCategories(false); | |
for(var i = 0; i < consent.length; i++) { | |
consGroupNumber = consent[i].replace('0_', ''); | |
switch(consGroupNumber) { | |
case '112': // Analytics | |
u.gdpr.setPreferencesValues({1: 1}); | |
break; | |
case '3': // Display Ad | |
u.gdpr.setPreferencesValues({3: 1}); | |
break; | |
case '4': // Personalization | |
u.gdpr.setPreferencesValues({6: 1}); | |
break; | |
} | |
} | |
if(u.gdpr.getSelectedCategories().length) { | |
u.view(u.data); | |
} | |
}; | |
addListener(window, 'consent.onetrust', readDataAndSetConsentPref); | |
})(window.utag); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment