Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update non-IAB compliant CMP example #792

Merged
merged 6 commits into from
Jun 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 67 additions & 29 deletions dev-docs/modules/consentManagement.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,49 +201,87 @@ At a high level this looks like:
Below is sample code for implementing the stub functions. Sample code for formatting the consent string may be obtained [here](https://github.com/appnexus/cmp).

{% highlight js %}
window.__cmp = function(command, version, callback) {
var iabConsentData; // build the IAB consent string
var gdprApplies; // true if gdpr Applies to the user, else false
var responseCode; // false if there was an error, else true
if (command === 'getConsentData') {
callback({consentData: iabConsentData, gdprApplies: gdprApplies}, responseCode);
} else if (command === 'getVendorConsents') {
callback({metadata: iabConsentData, gdprApplies: gdprApplies}, responseCode);
} else {
callback(undefined, false);
var iabConsentData; // build the IAB consent string
var gdprApplies; // true if gdpr Applies to the user, else false
var hasGlobalScope; // true if consent data was retrieved globally
var responseCode; // false if there was an error, else true
var cmpLoaded; // true if iabConsentData was loaded and processed
(function(window, document) {
function addFrame() {
if (window.frames['__cmpLocator'])
return;
if ( document.body ) {
var body = document.body,
iframe = document.createElement('iframe');
iframe.name = '__cmpLocator';
iframe.style.display = 'none';
body.appendChild(iframe);
} else {
setTimeout(addFrame, 5);
}
}
addFrame();
function cmpMsgHandler(event) {
try {
var json = event.data;
var msgIsString = typeof json === "string";
if ( msgIsString ) {
json = JSON.parse(json);
}
var call = json.__cmpCall;
if (call) {
window.__cmp(call.command, call.parameter, function(retValue, success) {
var returnMsg = {
__cmpReturn: {
returnValue: retValue, success: success, callId: call.callId
}
};
event.source.postMessage(msgIsString ? JSON.stringify(returnMsg) : returnMsg, '*');
});
}
} catch (e) {} // do nothing
}
};

// for framed scenarios
window.addEventListener('message', function(event) {
try {
var call = event.data.__cmpCall;
if (call) {
window.__cmp(call.command, call.parameter, function(retValue, success) {
var returnMsg = {
__cmpReturn: {
returnValue: retValue, success: success, callId: call.callId
}
};
event.source.postMessage(returnMsg, '*');
});
function cmpFunc = function(command, version, callback) {
if (command === 'ping') {
callback({gdprAppliesGlobally: gdprApplies, cmpLoaded: cmpLoaded}, responseCode);
} else if (command === 'getConsentData') {
callback({consentData: iabConsentData, gdprApplies: gdprApplies, hasGlobalScope: hasGlobalScope}, responseCode);
} else if (command === 'getVendorConsents') {
callback({metadata: iabConsentData, gdprApplies: gdprApplies, hasGlobalScope: hasGlobalScope}, responseCode);
} else {
callback(undefined, false);
}
} catch (e) {} // do nothing
});
};
if ( typeof (__cmp) !== 'function' ) {
window.__cmp = cmpFunc;
window.__cmp.msgHandler = cmpMsgHandler;
if ( window.addEventListener ) {
window.addEventListener('message', cmpMsgHandler, false);
} else {
window.attachEvent('onmessage', cmpMsgHandler);
}
}
})(window, document);
{% endhighlight %}

### Explanation of Parameters
**iabConsentData**
For how to generate the IAB consent string see the [IAB CMP 1.1 Spec](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework).
For how to generate the IAB consent string see the [IAB CMP 1.1 Spec](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework) and [IAB Consent String SDK](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/tree/master/Consent%20String%20SDK).

**gdprApplies**
How to generate the gdprApplies field:
- True if the current user is in the European Economic Area (EEA) OR if the publisher wants to have all traffic considered in-scope for GDPR
- False if it's known that the user is outside the EEA
- Leave the attribute unspecified if user's location is unknown

**hasGlobalScope**
This should be set as true if consent data was retrieved from global "euconsent" cookie, or was it publisher-specific. For general purpose, set this to false.

**responseCode**
This should be false if there was some error in the consent data, true otherwise. False is the same as calling the callback with no parameters.
This should be false if there was some error in the consent data, true otherwise. False is the same as calling the callback with no parameters.

**cmpLoaded**
This should be be set to true once parameters above are processed.

## List of GDPR compliant Adapters

Expand Down