8000 Integration examples: update the AMP creative by bretg · Pull Request #7911 · prebid/Prebid.js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Integration examples: update the AMP creative #7911

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

Merged
merged 2 commits into from
Jan 10, 2022
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
8000
Diff view
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