Skip to content

Commit 38cff0d

Browse files
authored
Various modules: consolidate page view ID logic (#14051)
* Page view ID. * Page view ID. * Removed console.log. * Removed unused import. * Improved example. * Fixed some tests.
1 parent 47b67e5 commit 38cff0d

File tree

19 files changed

+158
-74
lines changed

19 files changed

+158
-74
lines changed

integrationExamples/gpt/prebidServer_example.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@
8383

8484
<script>
8585
googletag.cmd.push(function() {
86-
var rightSlot = googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());
86+
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());
8787

88-
if (pbjs.libLoaded) { // Check if Prebid.js is loaded
88+
// Check if Prebid.js is loaded
89+
if (pbjs.libLoaded) {
8990
pbjs.que.push(function() {
9091
pbjs.setTargetingForGPTAsync();
9192
googletag.pubads().refresh();

integrationExamples/testBidder/testBidderBannerExample.html

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,51 @@
1111
const adUnits = [{
1212
mediaTypes: {
1313
banner: {
14-
sizes: [600, 500]
14+
sizes: [[320, 250], [300, 250]]
1515
}
1616
},
1717
code: adUnitCode,
1818
bids: [
19-
{bidder: 'testBidder', params: {}}
19+
{bidder: 'testBidder', params: {}},
20+
{bidder: 'kobler', params: {test: true}},
2021
]
21-
}]
22+
}];
23+
24+
function requestBids() {
25+
pbjs.requestBids({
26+
adUnitCodes: [adUnitCode],
27+
bidsBackHandler: function() {
28+
const bids = pbjs.getHighestCpmBids(adUnitCode);
29+
const winningBid = bids[0];
30+
const div = document.getElementById('banner');
31+
let iframe = div.querySelector('iframe')
32+
if (iframe === null) {
33+
iframe = document.createElement('iframe');
34+
iframe.frameBorder = '0';
35+
div.appendChild(iframe);
36+
}
37+
var iframeDoc = iframe.contentWindow.document;
38+
pbjs.renderAd(iframeDoc, winningBid.adId);
39+
}
40+
});
41+
}
42+
43+
function refreshBids() {
44+
pbjs.que.push(requestBids);
45+
}
46+
47+
function refreshPageViewId() {
48+
pbjs.que.push(function () {
49+
pbjs.refreshPageViewId()
50+
});
51+
}
2252

2353
pbjs.que.push(function () {
2454

55+
pbjs.setConfig({
56+
pageUrl: 'https://www.tv2.no/mening-og-analyse/14555348/'
57+
})
58+
2559
/**
2660
* BID RESPONSE SIMULATION SECTION START
2761
*
@@ -55,25 +89,15 @@
5589
*/
5690

5791
pbjs.addAdUnits(adUnits);
58-
pbjs.requestBids({
59-
adUnitCodes: [adUnitCode],
60-
bidsBackHandler: function() {
61-
const bids = pbjs.getHighestCpmBids(adUnitCode);
62-
const winningBid = bids[0];
63-
const div = document.getElementById('banner');
64-
let iframe = document.createElement('iframe');
65-
iframe.frameBorder = '0';
66-
div.appendChild(iframe);
67-
var iframeDoc = iframe.contentWindow.document;
68-
pbjs.renderAd(iframeDoc, winningBid.adId);
69-
}
70-
});
92+
requestBids();
7193
});
7294
</script>
7395
</head>
7496
<body>
7597
<h2>Prebid Test Bidder Example</h2>
98+
<p><button onclick="refreshBids()">Refresh Ad Units</button></p>
99+
<p><button onclick="refreshPageViewId()">Refresh page view ID</button></p>
76100
<h5>Banner ad</h5>
77101
<div id="banner"></div>
78102
</body>
79-
</html>
103+
</html>

libraries/adagioUtils/adagioUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const _ADAGIO = (function() {
2222
const w = getBestWindowForAdagio();
2323

2424
w.ADAGIO = w.ADAGIO || {};
25+
// TODO: consider using the Prebid-generated page view ID instead of generating a custom one
2526
w.ADAGIO.pageviewId = w.ADAGIO.pageviewId || generateUUID();
2627
w.ADAGIO.adUnits = w.ADAGIO.adUnits || {};
2728
w.ADAGIO.pbjsAdUnits = w.ADAGIO.pbjsAdUnits || [];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {deepSetValue} from '../../../src/utils.js';
2+
3+
export function setRequestExtPrebidPageViewIds(ortbRequest, bidderRequest) {
4+
deepSetValue(
5+
ortbRequest,
6+
`ext.prebid.page_view_ids.${bidderRequest.bidderCode}`,
7+
bidderRequest.pageViewId
8+
);
9+
}

libraries/pbsExtensions/processors/pbs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {setImpAdUnitCode} from './adUnitCode.js';
77
import {setRequestExtPrebid, setRequestExtPrebidChannel} from './requestExtPrebid.js';
88
import {setBidResponseVideoCache} from './video.js';
99
import {addEventTrackers} from './eventTrackers.js';
10+
import {setRequestExtPrebidPageViewIds} from './pageViewIds.js';
1011

1112
export const PBS_PROCESSORS = {
1213
[REQUEST]: {
@@ -21,7 +22,11 @@ export const PBS_PROCESSORS = {
2122
extPrebidAliases: {
2223
// sets ext.prebid.aliases
2324
fn: setRequestExtPrebidAliases
24-
}
25+
},
26+
extPrebidPageViewIds: {
27+
// sets ext.prebid.page_view_ids
28+
fn: setRequestExtPrebidPageViewIds
29+
},
2530
},
2631
[IMP]: {
2732
params: {

modules/carodaBidAdapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const spec = {
4040
);
4141
},
4242
buildRequests: (validBidRequests, bidderRequest) => {
43+
// TODO: consider using the Prebid-generated page view ID instead of generating a custom one
4344
topUsableWindow.carodaPageViewId = topUsableWindow.carodaPageViewId || Math.floor(Math.random() * 1e9);
4445
const pageViewId = topUsableWindow.carodaPageViewId;
4546
const ortbCommon = getORTBCommon(bidderRequest);

modules/cwireBidAdapter.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { registerBidder } from "../src/adapters/bidderFactory.js";
22
import { getStorageManager } from "../src/storageManager.js";
33
import { BANNER } from "../src/mediaTypes.js";
44
import {
5-
generateUUID,
65
getParameterByName,
76
isNumber,
87
logError,
@@ -27,11 +26,6 @@ export const BID_ENDPOINT = "https://prebid.cwi.re/v1/bid";
2726
export const EVENT_ENDPOINT = "https://prebid.cwi.re/v1/event";
2827
export const GVL_ID = 1081;
2928

30-
/**
31-
* Allows limiting ad impressions per site render. Unique per prebid instance ID.
32-
*/
33-
export const pageViewId = generateUUID();
34-
3529
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
3630

3731
/**
@@ -248,7 +242,7 @@ export const spec = {
248242
slots: processed,
249243
httpRef: referrer,
250244
// TODO: Verify whether the auctionId and the usage of pageViewId make sense.
251-
pageViewId: pageViewId,
245+
pageViewId: bidderRequest.pageViewId,
252246
networkBandwidth: getConnectionDownLink(window.navigator),
253247
sdk: {
254248
version: "$prebid.version$",

modules/kargoBidAdapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ function buildRequests(validBidRequests, bidderRequest) {
172172

173173
const page = {}
174174
if (validPageId) {
175+
// TODO: consider using the Prebid-generated page view ID instead of generating a custom one
175176
page.id = getLocalStorageSafely(CERBERUS.PAGE_VIEW_ID);
176177
}
177178
if (validPageTimestamp) {

modules/koblerBidAdapter.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
deepAccess,
3-
generateUUID,
43
getWindowSelf,
54
isArray,
65
isStr,
@@ -15,8 +14,6 @@ import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.j
1514

1615
const additionalData = new WeakMap();
1716

18-
export const pageViewId = generateUUID();
19-
2017
export function setAdditionalData(obj, key, value) {
2118
const prevValue = additionalData.get(obj) || {};
2219
additionalData.set(obj, { ...prevValue, [key]: value });
@@ -185,7 +182,7 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) {
185182
kobler: {
186183
tcf_purpose_2_given: purpose2Given,
187184
tcf_purpose_3_given: purpose3Given,
188-
page_view_id: pageViewId
185+
page_view_id: bidderRequest.pageViewId
189186
}
190187
}
191188
};

modules/ooloAnalyticsAdapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const prebidVersion = '$prebid.version$'
2222
const analyticsType = 'endpoint'
2323
const ADAPTER_CODE = 'oolo'
2424
const AUCTION_END_SEND_TIMEOUT = 1500
25+
// TODO: consider using the Prebid-generated page view ID instead of generating a custom one
2526
export const PAGEVIEW_ID = +generatePageViewId()
2627

2728
const {

0 commit comments

Comments
 (0)