Last active
July 3, 2020 04:06
-
-
Save mavaddat/310e3a9c63a003dff3509417ee640a73 to your computer and use it in GitHub Desktop.
Obtain and manage consumer consent for GDPR across digital ecosystem with Quantcast Choice. Details here: https://help.quantcast.com/hc/en-us/articles/360047075914-Choice-Universal-Tag-Implementation
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
<!-- Quantcast Choice. Consent Manager Tag v2.0 (for TCF 2.0) --> | |
<script type="text/javascript" async="true"> | |
(function() { | |
var host = window.location.hostname; | |
var element = document.createElement('script'); | |
var firstScript = document.getElementsByTagName('script')[0]; | |
var milliseconds = new Date().getTime(); | |
var url = 'https://quantcast.mgr.consensu.org' | |
.concat('/choice/', 'DffhEACkSgqrA', '/', host, '/choice.js') | |
.concat('?timestamp=', milliseconds); | |
var uspTries = 0; | |
var uspTriesLimit = 3; | |
element.async = true; | |
element.type = 'text/javascript'; | |
element.src = url; | |
firstScript.parentNode.insertBefore(element, firstScript); | |
function makeStub() { | |
var TCF_LOCATOR_NAME = '__tcfapiLocator'; | |
var queue = []; | |
var win = window; | |
var cmpFrame; | |
function addFrame() { | |
var doc = win.document; | |
var otherCMP = !!(win.frames[TCF_LOCATOR_NAME]); | |
if (!otherCMP) { | |
if (doc.body) { | |
var iframe = doc.createElement('iframe'); | |
iframe.style.cssText = 'display:none'; | |
iframe.name = TCF_LOCATOR_NAME; | |
doc.body.appendChild(iframe); | |
} else { | |
setTimeout(addFrame, 5); | |
} | |
} | |
return !otherCMP; | |
} | |
function tcfAPIHandler() { | |
var gdprApplies; | |
var args = arguments; | |
if (!args.length) { | |
return queue; | |
} else if (args[0] === 'setGdprApplies') { | |
if ( | |
args.length > 3 && | |
args[2] === 2 && | |
typeof args[3] === 'boolean' | |
) { | |
gdprApplies = args[3]; | |
if (typeof args[2] === 'function') { | |
args[2]('set', true); | |
} | |
} | |
} else if (args[0] === 'ping') { | |
var retr = { | |
gdprApplies: gdprApplies, | |
cmpLoaded: false, | |
cmpStatus: 'stub' | |
}; | |
if (typeof args[2] === 'function') { | |
args[2](retr); | |
} | |
} else { | |
queue.push(args); | |
} | |
} | |
function postMessageEventHandler(event) { | |
var msgIsString = typeof event.data === 'string'; | |
var json = {}; | |
try { | |
if (msgIsString) { | |
json = JSON.parse(event.data); | |
} else { | |
json = event.data; | |
} | |
} catch (ignore) {} | |
var payload = json.__tcfapiCall; | |
if (payload) { | |
window.__tcfapi( | |
payload.command, | |
payload.version, | |
function(retValue, success) { | |
var returnMsg = { | |
__tcfapiReturn: { | |
returnValue: retValue, | |
success: success, | |
callId: payload.callId | |
} | |
}; | |
if (msgIsString) { | |
returnMsg = JSON.stringify(returnMsg); | |
} | |
event.source.postMessage(returnMsg, '*'); | |
}, | |
payload.parameter | |
); | |
} | |
} | |
while (win) { | |
try { | |
if (win.frames[TCF_LOCATOR_NAME]) { | |
cmpFrame = win; | |
break; | |
} | |
} catch (ignore) {} | |
if (win === window.top) { | |
break; | |
} | |
win = win.parent; | |
} | |
if (!cmpFrame) { | |
addFrame(); | |
win.__tcfapi = tcfAPIHandler; | |
win.addEventListener('message', postMessageEventHandler, false); | |
} | |
}; | |
if (typeof module !== 'undefined') { | |
module.exports = makeStub; | |
} else { | |
makeStub(); | |
} | |
var uspStubFunction = function() { | |
var arg = arguments; | |
if (typeof window.__uspapi !== uspStubFunction) { | |
setTimeout(function() { | |
if (typeof window.__uspapi !== 'undefined') { | |
window.__uspapi.apply(window.__uspapi, arg); | |
} | |
}, 500); | |
} | |
}; | |
var checkIfUspIsReady = function() { | |
uspTries++; | |
if (window.__uspapi === uspStubFunction && uspTries < uspTriesLimit) { | |
console.warn('USP is not accessible'); | |
} else { | |
clearInterval(uspInterval); | |
} | |
}; | |
if (typeof window.__uspapi === 'undefined') { | |
window.__uspapi = uspStubFunction; | |
var uspInterval = setInterval(checkIfUspIsReady, 6000); | |
} | |
})(); | |
</script> | |
<!-- End Quantcast Choice. Consent Manager Tag v2.0 (for TCF 2.0) --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source
Determining & Executing Consent Code (TCF v2) – Quantcast Support
Help Center
Submit Help Request Sign In
Determining & Executing Consent Code (TCF v2)
Just like vendors, some publishers will need to wait for a consent signal before setting cookies or processing user personal data for one or more of the purposes they selected—if they choose consent as their legal basis for one or more of the purposes.
In order to retrieve consent, publishers need to update their website code to look for the consent signal. This can be done through the IAB TCFv2 API __tcfapi using the 'getTCData' command provided by the Choice CMP. The publisher will need to check for consent given for the desired purposes listed in the purpose field (tcData.purposes.consents). A publisher can claim purpose(s) under legitimate interest. If that is the case the publisher will need to check whether a user opted out of the purpose (tcData.purposes.legitimateInterests). More info can be found in the IAB Europe Transparency and Consent Framework JS API Specification.
Executing Code after Consent Collection
In order to perform an operation when the user has made a new choice of consents (the tcString has changed), use the following "__tcfapi" operation to register a callback:
The callback will be invoked with the TCData object as an argument whenever the TC string is changed and a new one is available. The TCData object will contain a CMP-assigned listenerId for the registered listener.
To remove the event listener you call call the __tcfapi using this command:
For more information please refer to the IAB Europe Transparency and Consent Framework JS API Specification.