-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration examples: update the AMP creative (#7911)
* 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
Showing
1 changed file
with
11 additions
and
33 deletions.
There are no files selected for viewing
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
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> |