amp-consent and IAB consent string implementation details

821 Views Asked by At

We have finished developing a CMP according to IAB TCFv2 and are struggling to integrate it with AMP, because amp-consent doesn't make the consent string available to the CMP prompt and ads.

Publisher code:

<amp-consent id="myUserConsent" layout="nodisplay">
<script type="application/json">{
    "consentInstanceId": "consent-id",
    "consentRequired": true,
    "promptUI": "consentDialog",
    "postPromptUI": "post-consent-ui",
    "checkConsentHref": "https://open-cmp.local:5003/consent/check",
    "onUpdateHref": "https://open-cmp.local:5003/consent/update"
}</script>
<div class="popupOverlay" id="consentDialog">
    <amp-iframe layout="fill" src="https://open-cmp.local:5003/demo/amp/cmp-frame.html"
                sandbox="allow-scripts allow-same-origin">
        <div placeholder>Loading</div>
    </amp-iframe>
</div>
<div id="post-consent-ui">
    <button on="tap:myUserConsent.prompt()">Update Consent</button>
</div>

The Iframe is sending back the consent string according to the user's settings:

window.parent.postMessage({
        type: 'consent-response',
        info: "the consent string",
        action: 'accept'
    }, '*');

According to AMP documentation, the consent string is made available to amp-ad and also to the CMP prompt when the user wants to make changes:

Client information passed to iframe When the iframe is created, the following information will be passed to the iframe via the name attribute.

but window.name is always set to a plain string which contains the name of the iframe, i.e. amp_iframe0, there is no JSON like data. I also tried window.context which is always undefined.

The second challenge is, how can I make sure that the consent string is made available in amp-ad and to other components? I tried a amp-iframe, but the consent string isn't there.

All the articles, discussions and docs in the web are a little bit confusing/outdated/inconsistent, I really appreciate if someone could point me in the right direction.

1

There are 1 best solutions below

0
On

Don't know if this is still open, but on AMP amp-ad will get an iframe hosted on ampproject.net.

As you can see here, there is a JSON feed inside of "name" AMP is using to transport those data for amp-ad tags:

enter image description here

As soon there is an amp-ad within the attribute "data-block-on-consent" and a cmp, window.context of this iframe will have properties for the tcf string, the "initialConsentValue"

enter image description here

But i would like to point you to this issue on github: https://github.com/ampproject/amphtml/issues/30385

Within this you should be able to act as in regular web and provide a _tcfapilocator frame, hopefully as I as a consumer would like to use it that way as this would be an IAB specified way...