Skip to content

Commit

Permalink
Integration examples: update the AMP creative (#7911)
Browse files Browse the repository at this point in the history
* fixing the AMP creative

There's no way the original version of this ever worked. AMP requires calling out to Prebid Cache. The original example was calling for Prebid.js, which isn't present in an AMP environment. 

I just copied the instructions at https://docs.prebid.org/adops/setting-up-prebid-for-amp-in-dfp.html

* added quotes
  • Loading branch information
bretg authored Jan 10, 2022
1 parent de3b797 commit 44f6bdb
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions integrationExamples/gpt/amp/creative.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
<!-- This script tag should be returned by your ad server -->

<script src="https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/creative.js"></script>
<script>
// This is the `renderAd` function from Prebid.js moved within the creative iframe
var renderAd = function (ev) {
var key = ev.message ? "message" : "data";
var data = {};
try {
data = JSON.parse(ev[key]);
} catch (e) {
// Do nothing. No ad found.
}
if (data.ad || data.adUrl) {
if (data.ad) {
document.write(data.ad);
document.close();
} else if (data.adUrl) {
document.write('<IFRAME SRC="' + data.adUrl + '" WIDTH="'+ data.width +'" HEIGHT="'+ data.height +'" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true"></IFRAME>');
document.close();
}
}
};
var ucTagData = {};
ucTagData.adServerDomain = "";
ucTagData.pubUrl = "%%PATTERN:url%%";
ucTagData.targetingMap = "%%PATTERN:TARGETINGMAP%%";
ucTagData.hbPb = "%%PATTERN:hb_pb%%";

var requestAdFromPrebid = function () {
var message = JSON.stringify({
message: 'Prebid creative requested: %%PATTERN:hb_adid%%',
adId: '%%PATTERN:hb_adid%%'
});
window.parent.postMessage(message, '*');
};

var listenAdFromPrebid = function () {
window.addEventListener("message", renderAd, false);
};

listenAdFromPrebid();
requestAdFromPrebid();
try {
ucTag.renderAd(document, ucTagData);
} catch (e) {
console.log(e);
}
</script>

0 comments on commit 44f6bdb

Please sign in to comment.