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

Improvement/prebid iframes amp pages #1119

Merged
merged 2 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions integrationExamples/gpt/amp/amp_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>Welcome to the mobile web</h1>
height="250"
layout="fixed"
type="doubleclick"
json='{"prebid":{"requestBidsDuration":1000,"adUnits":[{"code":"/19968336/header-bid-tag-1","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"4799418","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]},{"code":"/19968336/header-bid-tag-2","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"4799418","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]}]}}'
json='{"prebid":{"requestBidsDuration":1000,"adUnits":[{"code":"/19968336/header-bid-tag-1","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"10433394","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]},{"code":"/19968336/header-bid-tag-2","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"10433394","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]}]}}'
data-slot="/19968336/header-bid-tag-1">
</amp-ad>

Expand All @@ -64,7 +64,7 @@ <h1>Welcome to the mobile web</h1>
height="250"
layout="fixed"
type="doubleclick"
json='{"prebid":{"requestBidsDuration":1000,"adUnits":[{"code":"/19968336/header-bid-tag-1","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"4799418","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]},{"code":"/19968336/header-bid-tag-2","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"4799418","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]}]}}'
json='{"prebid":{"requestBidsDuration":1000,"adUnits":[{"code":"/19968336/header-bid-tag-1","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"10433394","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]},{"code":"/19968336/header-bid-tag-2","sizes":[[300,250],[300,600],[300,250],[100,100]],"bids":[{"bidder":"appnexusAst","params":{"placementId":"10433394","dealId":"some deal!"}},{"bidder":"aol","params":{"network":"10077.1","placement":3671670}},{"bidder":"sovrn","params":{"tagid":"315045"}}]}]}}'
data-slot="/19968336/header-bid-tag-2">
</amp-ad>

Expand Down
47 changes: 28 additions & 19 deletions integrationExamples/gpt/amp/remote.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<!-- start Prebid.js AMP integration -->

<script>
// The Prebid global must match Prebid.js setting
// The Prebid global must match Prebid.js setting. This example file is not preprocessed so below we refer to global as `pbjs`.
var $$PREBID_GLOBAL$$ = pbjs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just make this pbjs? seems confusing.

var prebidSrc = 'https://publisher.com:9999/build/dev/prebid.js';
var adUnits;
Expand Down Expand Up @@ -71,22 +71,26 @@
}

function getTargeting(slot) {
var targeting = window.context.master.pbjs.getAdserverTargeting()[slot];
var targeting = window.context.master.pbjs.getAdserverTargeting()[slot] || {};
for (var key in targeting) {
if (targeting.hasOwnProperty(key)) {
targeting[key] = [targeting[key]];
}
}
targeting['prebid_amp'] = ['true'];

if (Object.keys(targeting).length) {
// only set this key if prebid targeting is present
targeting['prebid_amp'] = ['true'];
}
return targeting;
}

function initAdserver() {
function initAdserver() {
var i;
var adCalls = window.context.master.adCalls;
var adCallsLength = adCalls.length;
for (i = 0; i < adCallsLength; i++) {
adCalls.pop()();
var prebidAdCalls = window.context.master.prebidAdCalls;
var len = prebidAdCalls.length;
for (i = 0; i < len; i++) {
prebidAdCalls.pop()();
}
}

Expand Down Expand Up @@ -128,18 +132,23 @@
* iframes. For more info see: https://github.com/ampproject/amphtml/blob/e5501a30adf15c8fef049729f5e0e3137dbb18ca/3p/integration.js#L252
*/
draw3p(function(config, done) {
if (typeof window.context.master.adCalls === 'undefined') {
window.context.master.adCalls = [];
}
if (window.context && window.context.isMaster && config.prebid) {
var prebid = config.prebid;
adUnits = prebid.adUnits;
requestBidsDuration = prebid.requestBidsDuration;
loadPrebidJS();
if (config.prebid) {
if (typeof window.context.master.prebidAdCalls === 'undefined') {
window.context.master.prebidAdCalls = [];
}
window.context.master.adCalls.push(setTargeting.bind(null, config, done));
}, ['doubleclick'], ['publisher.com']);
// the first array contains ad networks used, the second domains allows to load this file in an iframe
if (window.context && window.context.isMaster) {
var prebid = config.prebid;
adUnits = prebid.adUnits;
requestBidsDuration = prebid.requestBidsDuration;
loadPrebidJS();
}
window.context.master.prebidAdCalls.push(setTargeting.bind(null, config, done));
} else {
// if the slot doesn't have prebid config then fire callback
done(config);
}
}, ['doubleclick', 'taboola'], ['publisher.com']);
// the first array contains ad networks used, the second contains domains allowed to load this file in an iframe

listenAdRequestFromCreative();
</script>
Expand Down