forked from prebid/prebid.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamazon_example.html
More file actions
276 lines (200 loc) · 7.67 KB
/
Copy pathamazon_example.html
File metadata and controls
276 lines (200 loc) · 7.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<html>
<head>
<script>
var rightSlotCode = '/19968336/header-bid-tag-0';
var rightDivId = 'div-gpt-ad-1438287399331-0';
var rightSlotSizes = [[300, 250], [300, 600]];
var topSlotCode = '/19968336/header-bid-tag1';
var topDivId = 'div-gpt-ad-1438287399331-1'
var topSlotSizes = [[728, 90], [970, 90]];
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var PREBID_TIMEOUT = 1000;
var date = new Date().getTime();
function initAdserver() {
if (!pbjs.initAdserverSet){
//load GPT library here
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
}
pbjs.initAdserverSet = true;
};
// Load GPT when timeout is reached.
setTimeout(initAdserver, PREBID_TIMEOUT);
pbjs.que.push(function(){
var A9Adaptor = function A9Adaptor() {
return {
callBids: function(p) {
pbjs.loadScript('//c.amazon-adsystem.com/aax2/amzn_ads.js', function() {
amznads.getAdsCallback(p.bids[0].params.aId, function() {
// Indicate bids are back here:
pbjs.bidsAvailableForAdapter('amazon');
});
});
}
};
};
pbjs.registerBidAdapter(A9Adaptor, 'amazon');
var adUnit1 = {
code: rightSlotCode,
//code: rightDivId,
sizes: rightSlotSizes,
bids: [{
bidder: 'amazon',
params: {
aId : 3030
}
}]
}
//can add a single ad unit
//pbjs.addAdUnit(adUnit1);
var adUnit2 = {
code: topSlotCode,
//code : topDivId,
sizes: topSlotSizes,
bids: [{
bidder: 'appnexus',
params: {
placementId : '5215561'
//memberId : '1234',
//invCode : '7454'
}
}]
};
//add array of ad units
var arr = [adUnit2, adUnit1];
pbjs.addAdUnits([adUnit2, adUnit1]);
pbjs.bidderSettings =
{
appnexus: {
alwaysUseBid : true,
adserverTargeting: [{
key: "hb_bidder",
val: function(bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: "hb_adid",
val: function(bidResponse) {
return bidResponse.adId;
}
}, {
key: "hb_pb",
val: function(bidResponse) {
return bidResponse.pbMg;
}
}, {
key: "hb_size",
val: function(bidResponse) {
return bidResponse.getSize();
}
}]
}
};
pbjs.requestBids({
/* The bidsBack function will be called when either timeout is
reached, or when all bids come back, whichever happens sooner.
*/
bidsBackHandler: function(bidResponses) {
//initAdserver();
//
//this never get's executed, because we don't register bids back from amazon adapter
//alert(bidResponse);
var currentTime = new Date().getTime();
console.log('TIME for callback ===== ' + (currentTime-date));
initAdserver()
},
/* You can specify specific `adUnitCodes` to only request bids
for certain ad units.
adUnitCodes: ['code1', 'code2']
*/
/* You can also make one off bid requests for the given `adUnits`.
adUnits: [adUnit2, adUnit1]
*/
/* The bidsBackHandler will be executed either when all bids are
back, or when the timeout is reached.
timeout: 1000
*/
});
});
(function() {
var d = document, pbs = d.createElement("script"), pro = d.location.protocal; pbs.type = "text/javascript";
//pbs.src = (pro ? 'https' : 'http') + '://cdn.host.com/prebid.min.js';
//pbs.src = 'http://mkendall.devnxs.net/prebid.js'
pbs.src = 'http://acdn.adnxs.com/prebid/prebid.js';
//pbs.src = '../dist/prebid.js'
var target = document.getElementsByTagName("head")[0];
target.insertBefore(pbs, target.firstChild);
})();
//prbEl.src = 'http://cdn.adnxs.com/tag/v/prebid/2.1.1/prebid.min.js';
/*
googletag.cmd.push(function() {
googletag.pubads().setTargeting('amtest2', ["a728x90p14", "vp1"])
});
*/
</script>
<script>
googletag.cmd.push(function() {
var rightSlot = googletag.defineSlot(rightSlotCode, rightSlotSizes, 'div-gpt-ad-1438287399331-0').addService(googletag.pubads());
var topSlot = googletag.defineSlot(topSlotCode, topSlotSizes, 'div-gpt-ad-1438287399331-1').addService(googletag.pubads());
//'div-gpt-ad-1438287399331-1'
pbjs.que.push(function(){
pbjs.setTargetingForGPTAsync();
amznads.setTargetingForGPTAsync('amznslots');
console.log('Are all bids available? : ' + pbjs.allBidsAvailable());
console.log('Targeting params:')
console.log(pbjs.getAdserverTargeting());
console.log('Dumping all bid objects to console:');
console.log(pbjs.getBidResponses());
});
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
function refreshBids(){
pbjs.que.push(function(){
/*
pbjs.requestBids({
timeout: 500,
bidsBackHandler : function(){
callGPT();
}
});
*/
pbjs.requestBids();
});
}
function callGPT(){
console.log('executing inside pbjs object');
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
console.log(pbjs.getBidResponses());
}
</script>
</head>
<body>
<h2>Prebid.js Test3</h2>
<!-- /19968336/pbjs-right1-300x250-300x600 -->
<div id='div-gpt-ad-1438287399331-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1438287399331-0'); });
</script>
</div>
<!-- /19968336/PBJS-top-728x90-970x90 -->
<div id='div-gpt-ad-1438287399331-1'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1438287399331-1'); });
</script>
</div>
<button onclick="refreshBids()">Refresh Bids</button>
</body>
</html>