-
Notifications
You must be signed in to change notification settings - Fork 2
/
quick-start.html
executable file
·491 lines (472 loc) · 18 KB
/
quick-start.html
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="Header Bidding, Framework, HeaderBidding, Pubfood">
<title>Quick Start - Implementing Header Bidding</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="styles.css" rel="stylesheet">
<style>
.content ul ul {
list-style: none;
}
#section-ip-2 li {
background-image: none;
margin: 0;
}
#div-rail {
font-family: monospace;
}
#div-rail h3 {
font-size: 15px;
font-weight: bold;
}
#div-rail h4 {
font-size: 13px;
font-weight: bold;
}
#div-rail p {
margin: 0;
}
.loose li {
height:4em;
}
.loose span.code-ref {
margin-left: 60px;
}
#theAd {
margin: 0 0 60px 60px;
}
</style>
<script src="/pubfood.min.js"></script>
<script>
// global for the auction provider
window.auctionProviderOne = window.auctionProviderOne || {};
auctionProviderOne.cmd = auctionProviderOne.cmd || [];
// globals for all bid providers
window.bidProviderOne = window.bidProviderOne || {};
bidProviderOne.cmd = bidProviderOne.cmd || [];
var food = new pubfood();
food.addSlot({
name: '2476204-rail',
elementId: 'div-rail',
sizes: [[300, 250]],
bidProviders: ['bidProviderOne']
});
food.addBidProvider({
name: 'bidProviderOne',
libUri: '/simulated-bid-provider/bidProviderOne.js',
init: function(slots, pushBid, done) {
bidProviderOne.cmd.push(function() {
var encodedAvailability = encodeURIComponent('2476204-rail.650.300x250');
bidProviderOne.init('availability=' + encodedAvailability);
});
bidProviderOne.cmd.push(function() {
var getSize = function (raw) {
var sizeSplit = raw.split('x');
return [parseInt(sizeSplit[0], 10), parseInt(sizeSplit[1], 10)];
};
var parts = bidProviderOne.getAvailable().split('.');
pushBid({
slot: parts[0],
value: parts[1],
sizes: getSize(parts[2]),
label: 'avg_price',
targeting: {
pvd1: 'targeting'
}
});
done();
});
},
refresh: function(slots, pushBid, done) {
}
});
food.setAuctionProvider({
name: 'auctionProviderOne',
libUri: '/simulated-auction-provider/auctionProviderOne.js',
init: function(targeting, done) {
auctionProviderOne.cmd.push(function() {
var i, key;
for (i = 0; i < targeting.length; i++) {
var tgtObject = targeting[i];
if (tgtObject.name) {
var apSlot = auctionProviderOne.defineSlot(tgtObject.name, tgtObject.sizes, tgtObject.elementId);
// set slot level targeting
for (key in tgtObject.targeting) {
apSlot.setTargeting(key, tgtObject.targeting[key]);
}
} else {
// set page level targeting
for (key in tgtObject.targeting) {
auctionProviderOne.setTargeting(key, tgtObject.targeting[key]);
}
}
}
});
auctionProviderOne.cmd.push(function() {
auctionProviderOne
.enableSingleRequest()
.enableServices();
});
done();
},
refresh: function(targeting, done) {
done();
}
});
food.timeout(1500);
food.observe(function(ev) {
console.log(ev);
});
food.start();
</script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- begin header -->
<div class="top-wrapper-outer">
<div id="top-wrapper">
<div class="top-w-1">
<div id="logo"><a href="/"><img src="images/logo.png" width="162" height="142" title="Pubfood" alt="Pubfood logo"></a></div>
</div><!-- end .top-w-1 -->
<div class="top-w-2">
<div id="main-nav">
<ul>
<li><a href="/quick-start" class="mn-link-active">Quick Start</a></li>
<li><a href="/integration-playbook">Integration Playbook</a></li>
<li><a href="/api-reference">API Reference</a></li>
<li><a href="https://github.com/pubfood/pubfood" target="_blank">GitHub</a></li>
<li><a href="mailto:[email protected]?subject=Invite%20Request:%20Pubfood.js%20Slack%20Channel">Slack</a></li>
<li><a href="/testimonials">Testimonials</a></li>
</ul>
</div><!-- end #main-nav -->
</div><!-- end .top-w-2 -->
<div class="clear-float"></div>
<div id="mn-toggle-link"><a href="javascript:void(0)" title="show main navigation"></a></div>
</div><!-- end #top-wrapper -->
</div><!-- end .top-wrapper-outer -->
<!-- end header -->
<div id="section-ip-1" class="content">
<!-- begin section connector :: needed to complete header -->
<div class="section-connector-1"><img src="images/half-circle-1.png" width="120" height="35" alt="half circle" /></div>
<!-- end section connector :: needed to complete header -->
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
</div>
</div><!-- end .row -->
</div><!-- end .container-fluid -->
</div><!-- end #section-ip-1 -->
<div id="section-ip-2" class="content">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<h3>Getting started with the Pubfood.js framework</h3>
<div class="summary">
<h4><em>Quick Summary</em></h4>
<div class="step-text">
<ul class="loose">
<li>
Include the Pubfood JavaScript library in your code.<br/>
<b><span class="code-ref"><script src="/pubfood.min.js"></script></span></b>
</li>
<li>
Define slots and which partner may bid for them.<br/>
<b><span class="code-ref">food.addSlot(...);</span></b>
</li>
<li>
Define or copy your bidding partner JavaScript code.<br/>
<b><span class="code-ref">food.addBidProvider(...);</span></b>
</li>
<li>
Define or copy your ad server JavaScript code to send bids to auction.<br/>
<b><span class="code-ref">food.setAuctionProvider(...);</span></b>
</li>
<li>
Set a timeout for all bidders to submit a bid.<br/>
<b><span class="code-ref">food.timeout(...);</span></b>
</li>
<li>
And start the pubfood auction.<br/>
<b><span class="code-ref">food.start();</span></b>
</li>
<li>
Define where to display your ad.<br/>
<b><span class="code-ref">food.observe('AUCTION_POST_RUN', ...);</span></b>
</li>
</ul>
And finally:
<ul>
<li>
On each result received from a bidder, call the <b>pushBid({...});</b> callback to register the bid.
</li>
<li>
When bidding is finished, call the <b>done();</b> callback to process the results.
</li>
</ul>
</div>
</div>
<h3>Here is a live example:</h3>
<div class="example">
<div id="theAd" class="code-sample">
<pre id="div-rail">[Winning ad creative will appear here]</pre>
<script>
// Note: this auction provider requires the `display` to be called after the div is available
food.observe('AUCTION_POST_RUN', function() {
auctionProviderOne.cmd.push(function() {
auctionProviderOne.display('div-rail');
});
});
</script>
</div>
<p>How did this ad get here? By following these steps...</p>
</div>
<h3>Detailed Instructions</h3>
<div id="steps">
<div class="step">
<h4>1. Include the Pubfood.js library in your site code</h4>
<div class="step-text">To execute the following steps in your own code, you will need to include the Pubfood JavaScript library.</div>
<div class="code-sample">
<b><a href="https://github.com/pubfood/pubfood/tree/master/dist">https://github.com/pubfood/pubfood/tree/master/dist</a></b>
<pre id="step0-code" class="prettyprint linenums"><script src="/pubfood.min.js"></script>
<script>/* Or, inline pubfood.min.js in your code */</script></pre>
</div>
</div>
<div class="step">
<h4>2. Define slots</h4>
<div class="step-text">You will tell Pubfood.js which of your ad server slots are available for bidding and which partners may bid for them.</div>
<div class="code-sample">
<pre id="step1-code" class="prettyprint linenums">var food = new pubfood();
food.addSlot({
name: '2476204-rail',
elementId: 'div-rail',
sizes: [[300, 250]],
bidProviders: ['bidProviderOne']
});</pre>
</div>
</div>
<div class="step">
<h4>3. Define bidding partner</h4>
<div class="step-text">
Pubfood does not need to know much about how your bid provider works.
<ul>
<li><span class="lines-ref">Line 2</span> - The bidder name</li>
<li><span class="lines-ref">Line 3</span> - The bid provider JavaScript library to load</li>
<li><span class="lines-ref">Line 4</span> - The function to initialize bids</li>
<li><span class="lines-ref">Line 15</span> - Submit a bid with the <span class="code-ref">pushBid({});</span> callback</li>
<li><span class="lines-ref">Line 24</span> - Notify Pubfood.js with the <span class="code-ref">done();</span> callback</li>
<li><span class="lines-ref">Line 27</span> - The function to refresh bids</li>
</ul>
</div>
<div class="code-sample">
<pre id="step2-code" class="prettyprint linenums">food.addBidProvider({
name: 'bidProviderOne',
libUri: '/simulated-bid-provider/bidProviderOne.js',
init: function(slots, pushBid, done) {
bidProviderOne.cmd.push(function() {
var encodedAvailability = encodeURIComponent('2476204-rail.650.300x250');
bidProviderOne.init('availability=' + encodedAvailability);
});
bidProviderOne.cmd.push(function() {
var getSize = function (raw) {
var sizeSplit = raw.split('x');
return [parseInt(sizeSplit[0], 10), parseInt(sizeSplit[1], 10)];
};
var parts = bidProviderOne.getAvailable().split('.');
pushBid({
slot: parts[0],
value: parts[1],
sizes: getSize(parts[2]),
label: 'avg_price',
targeting: {
pvd1: 'targeting'
}
});
done();
});
},
refresh: function(slots, pushBid, done) {
}
});</pre>
</div>
</div>
<div class="step">
<h4>4. Define your ad server</h4>
<div class="step-text">
Set your auction provider that will receive bid targeting and send the targeting to auction in your ad server.
<ul>
<li><span class="lines-ref">Line 2</span> - The auction provider name</li>
<li><span class="lines-ref">Line 3</span> - The auction provider JavaScript library to load</li>
<li><span class="lines-ref">Line 4</span> - The function to initialize the auction</li>
<li><span class="lines-ref">Line 28</span> - Notify Pubfood.js with the <span class="code-ref">done();</span> callback</li>
<li><span class="lines-ref">Line 30</span> - The function to refresh with a new auction</li>
</ul>
</div>
<div class="code-sample">
<pre id="step3-code" class="prettyprint lang-js linenums">food.setAuctionProvider({
name: 'auctionProviderOne',
libUri: '/simulated-auction-provider/auctionProviderOne.js',
init: function(targeting, done) {
var i, key;
for (i = 0; i < targeting.length; i++) {
var tgtObject = targeting[i];
if (tgtObject.name) {
var apSlot = auctionProviderOne.defineSlot(tgtObject.name, tgtObject.sizes, tgtObject.elementId);
// set slot level targeting
for (key in tgtObject.targeting) {
apSlot.setTargeting(key, tgtObject.targeting[key]);
}
} else {
// set page level targeting
for (key in tgtObject.targeting) {
auctionProviderOne.setTargeting(key, tgtObject.targeting[key]);
}
}
}
});
auctionProviderOne.cmd.push(function() {
auctionProviderOne
.enableSingleRequest()
.enableServices();
});
done();
},
refresh: function(targeting, done) {
done();
}
});</pre>
</div>
</div>
<!--div class="step">
<h4>5. Define when to display ads</h4>
<div class="step-text">
Set your auction provider that will receive bid targeting and send the targeting to auction in your ad server.
<ul>
<li><span class="lines-ref">Line 2</span> - The auction provider name</li>
<li><span class="lines-ref">Line 3</span> - The auction provider JavaScript library to load</li>
<li><span class="lines-ref">Line 4</span> - The function to initialize the auction</li>
<li><span class="lines-ref">Line 29</span> - Notify Pubfood.js with the <span class="code-ref">done();</span> callback</li>
<li><span class="lines-ref">Line 31</span> - The function to refresh with a new auction</li>
</ul>
</div>
<div class="code-sample">
<pre id="step4-code" class="prettyprint lang-js linenums">food.setAuctionProvider({
name: 'auctionProviderOne',
libUri: '/simulated-auction-provider/auctionProviderOne.js',
init: function(bids, done) {
auctionProviderOne.cmd.push(function() {
var i, key;
for (i = 0; i < bids.length; i++) {
var bid = bids[i];
if (bid.type === 'page') {
// set page level targeting
for (key in bid.targeting) {
auctionProviderOne.setTargeting(key, bid.targeting[key]);
}
}
if (bid.type === 'slot') {
var apSlot = auctionProviderOne.defineSlot(bid.name, bid.sizes, bid.elementId);
// set slot level targeting
for (key in bid.targeting) {
apSlot.setTargeting(key, bid.targeting[key]);
}
}
}
});
auctionProviderOne.cmd.push(function() {
auctionProviderOne
.enableSingleRequest()
.enableServices();
});
done();
},
refresh: function(bids, done) {
}
});</pre>
</div>
</div-->
<div class="step">
<h4>5. Start the Pubfood.js auction</h4>
<div class="step-text">
Starting a Pubfood.js auction will initiate and orchestrate the steps defined above.
<ul>
<li><span class="lines-ref">Line 1</span> - Bidders need to respond within this time</li>
<li><span class="lines-ref">Line 2</span> - We can observe all events for debugging</li>
<li><span class="lines-ref">Line 5</span> - Start the auction</li>
</ul>
</div>
<div class="code-sample">
<pre id="step4-code" class="prettyprint lang-js linenums">food.timeout(1500);
food.observe(function(ev) {
console.log(ev);
});
food.start();</pre>
</div>
</div>
</div>
<div class="step">
<h4>6. Define when to display ads</h4>
<div class="step-text">
When Pubfood.js has completed the auction orchestration, it will raise an event to indicate ads are ready to display.
<ul>
<li><span class="lines-ref">Line 1</span> - Observe the auction provider</li>
<li><span class="lines-ref">Line 3</span> - Finally, the auction provider will display the ad</li>
</ul>
</div>
<div class="code-sample">
<pre id="step5-code" class="prettyprint lang-js linenums">food.observe('AUCTION_POST_RUN', function() {
auctionProviderOne.cmd.push(function() {
auctionProviderOne.display('div-rail');
});
});</pre>
</div>
</div>
<p>
<span style="font-size: larger; font-weight: bold">Nicely done.</span>
You completed this quick tutorial.<br/>
<a href="#theAd">Click here for a sample of the rendered ad.</a><br/>
See the <a href="/api-reference">API REFERENCE</a> for more.
</p>
</div>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=sons-of-obsidian"></script>
</div><!-- end .row -->
</div><!-- end .container-fluid -->
</div><!-- end #section-ip-2 -->
<!-- begin footer -->
<div class="footer-wrapper-outer">
<div id="footer-wrapper">
<div id="footer-logo">
<img class="f-logo-1" src="images/logo.png" width="162" height="142" alt="Pubfood logo" />
<img class="f-logo-2" src="images/logo-2.png" width="100" height="88" alt="Pubfood logo - smaller size" />
</div>
<ul>
<li><a href="https://github.com/pubfood/pubfood" target="_blank">GitHub</a></li>
<!-- <li><a href="#">Contact Us</a></li> -->
<li><a href="mailto:[email protected]?subject=Invite%20Request%3A%20Pubfood.js%20Slack%20Channel">Join the Pubfood.js Slack</a></li>
<li><a href="https://twitter.com/yieldbot" target="_blank"><img src="images/icon-twitter.png" width="28" height="24" alt="Twitter" /></a></li>
</ul>
<p><span>©2015 Pubfood.js</span> <span>All Rights Reserved</span></p>
</div><!-- end #footer-wrapper -->
</div><!-- end .footer-wrapper-outer -->
<!-- end footer -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<!-- begin Google Analytics code -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-69476533-1', 'pubfood.org');
ga('send', 'pageview');
</script>
<!-- end Google Analytics code -->
</body>
</html>