diff --git a/demos/vanilla/nocookies/targeting/prebid.html.tpl b/demos/vanilla/nocookies/targeting/prebid.html.tpl index f4b6d29..a5155bd 100644 --- a/demos/vanilla/nocookies/targeting/prebid.html.tpl +++ b/demos/vanilla/nocookies/targeting/prebid.html.tpl @@ -29,9 +29,13 @@ cookies: false, node: "${DCN_NODE}", legacyHostCache: "${DCN_LEGACY_HOST_CACHE}", + initTargeting: true, }); optable.instance.tryIdentifyFromParams(); + + // Create a ref for RTD module to use SDK. + optable.prebid_instance = optable.instance; }); @@ -43,13 +47,6 @@ optable.instance.installGPTEventListeners(); }); - // Try to fetch and cache targeting data from DCN: - optable.cmd.push(function () { - optable.instance.targeting().catch((err) => { - console.log("[OptableSDK] targeting() exception: " + err.message); - }); - }); - // Set up GPT: window.googletag = window.googletag || { cmd: [] }; googletag.cmd.push(function () { @@ -75,94 +72,92 @@ "/22081946781/web-sdk-demo-gam360/footer-ad": [[728, 90]], }; - var adUnits = [ - { - code: "/22081946781/web-sdk-demo-gam360/header-ad", - mediaTypes: { - banner: { - sizes: bannerSizes["/22081946781/web-sdk-demo-gam360/header-ad"], - }, + var adUnits = [ + { + code: "/22081946781/web-sdk-demo-gam360/header-ad", + mediaTypes: { + banner: { + sizes: bannerSizes["/22081946781/web-sdk-demo-gam360/header-ad"], }, - bids: [ - { - bidder: "districtmDMX", - params: { - dmxid: "/22081946781/web-sdk-demo-gam360/header-ad", - memberid: "102034", - }, - }, - ], }, - { - code: "/22081946781/web-sdk-demo-gam360/box-ad", - mediaTypes: { - banner: { - sizes: bannerSizes["/22081946781/web-sdk-demo-gam360/box-ad"], - }, + bids: [ + { + bidder: "pubmatic", + params: { + publisherId: "156209", // Example: PubMatic test publisher ID + } + } + ], + }, + { + code: "/22081946781/web-sdk-demo-gam360/box-ad", + mediaTypes: { + banner: { + sizes: bannerSizes["/22081946781/web-sdk-demo-gam360/box-ad"], }, - bids: [ - { - bidder: "districtmDMX", - params: { - dmxid: "/22081946781/web-sdk-demo-gam360/box-ad", - memberid: "102034", - }, - }, - ], }, - { - code: "/22081946781/web-sdk-demo-gam360/footer-ad", - mediaTypes: { - banner: { - sizes: bannerSizes["/22081946781/web-sdk-demo-gam360/footer-ad"], - }, + bids: [ + { + bidder: "pubmatic", + params: { + publisherId: "156209", + } + } + ], + }, + { + code: "/22081946781/web-sdk-demo-gam360/footer-ad", + mediaTypes: { + banner: { + sizes: bannerSizes["/22081946781/web-sdk-demo-gam360/footer-ad"], }, - bids: [ - { - bidder: "districtmDMX", - params: { - dmxid: "/22081946781/web-sdk-demo-gam360/footer-ad", - memberid: "102034", - }, - }, - ], }, - ]; + bids: [ + { + bidder: "pubmatic", + params: { + publisherId: "156209", + } + } + ], + } + ]; function initAdserver() { if (pbjs.initAdserverSet) return; pbjs.initAdserverSet = true; - googletag.cmd.push(function () { - pbjs.setTargetingForGPTAsync && pbjs.setTargetingForGPTAsync(); + const disableGamTargeting = localStorage.getItem("disableGamTargeting") === "true"; + console.log("[OptableSDK] Reading 'disableGamTargeting' from localstorage: " + disableGamTargeting); - // Setup page-level GAM targeting from any cached targeting data, and load GAM ads: - optable.cmd.push(function () { - const tdata = optable.instance.targetingKeyValuesFromCache(); - - if (tdata) { - for (const [key, values] of Object.entries(tdata)) { - googletag.pubads().setTargeting(key, values); - console.log("[OptableSDK] googletag.pubads().setTargeting(" + key + ", [" + values + "])"); - } + googletag.cmd.push(function () { + if (disableGamTargeting) { + console.log("[OptableSDK] Skipping pbjs.setTargetingForGPTAsync() because disableGamTargeting is set to true"); + } else { + pbjs.setTargetingForGPTAsync && pbjs.setTargetingForGPTAsync(); + console.log("[OptableSDK] pbjs.setTargetingForGPTAsync()"); } - googletag.pubads().refresh(); - console.log("[OptableSDK] googletag.pubads().refresh()"); - }); }); } pbjs.que.push(function () { optable.cmd.push(function () { - const ortb2 = optable.instance.prebidORTB2FromCache(); - pbjs.mergeConfig({ - ortb2, + debug: true, priceGranularity: "low", userSync: { iframeEnabled: true, - enabledBidders: ["districtmDMX"], + enabledBidders: ["pubmatic"], + }, + realTimeData: { + auctionDelay: 400, + dataProviders: [ + { + name: 'optable', + waitForIt: true, // should be true, otherwise the auctionDelay will be ignored + }, + ], }, }); pbjs.addAdUnits(adUnits); @@ -220,24 +215,55 @@
- Shows how to load active cohorts for a visitor and pass them to Prebid.js via - mergeConfig. - It's assumed in this example that your primary ad server is - Google Ad Manager (GAM) and that you are integrated with it - using the - Google Publisher Tag (GPT), so - we also pass matching active cohorts to GAM. + This demo demonstrates how to integrate Optable's targeting capabilities with Prebid.js using the + OptableRTD module. + The implementation assumes Google Ad Manager (GAM) as the primary ad server, integrated via + Google Publisher Tag (GPT).
+ +
- In this example, we use the prebidORTB2FromCache() API to retrieve any targeting data from browser
- LocalStorage, in order to pass it to Prebid.js via seller defined audiences. We also call the SDK targeting API
- which will fetch the latest targeting data from our DCN and cache it locally for later use. Since these
- two events happen asynchronously, it's possible that the targeting data passed to GAM is slightly outdated.
- To ensure ad targeting accuracy, it is recommended to call targeting to update the local cache on
- page load.
+ The Prebid.js configuration requires minimal setup. Here's the essential configuration:
pbjs.mergeConfig({
+ debug: true,
+ priceGranularity: "low",
+ userSync: {
+ iframeEnabled: true,
+ enabledBidders: ["pubmatic"]
+ },
+ realTimeData: {
+ auctionDelay: 400,
+ dataProviders: [{
+ name: 'optable',
+ waitForIt: true // Required to respect auctionDelay
+ }]
+ }
+});
+
+ targeting
+ on page load to update the local cache, as the RTD module only uses cached values.
+ localStorage.disableGamTargeting = "true"
+ before page load to prevent the SDK from sending targeting data to GAM.
+