-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename dynamicAdBoost to dynamicAdBoostRtdProvider
dynamicAdBoost is now submodule of the rtd
- Loading branch information
1 parent
75fa622
commit 325d061
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* The {@link module:modules/realTimeData} module is required | ||
* @module modules/dynamicAdBoost | ||
* @requires module:modules/realTimeData | ||
*/ | ||
|
||
import { submodule } from '../src/hook.js' | ||
import { loadExternalScript } from '../src/adloader.js'; | ||
import { getGlobal } from '../src/prebidGlobal.js'; | ||
import { deepAccess, deepSetValue, isEmptyStr } from '../src/utils.js'; | ||
|
||
const MODULE_NAME = 'dynamicAdBoost'; | ||
const SCRIPT_URL = 'https://adxbid.info'; | ||
// Options for the Intersection Observer | ||
const dabOptions = { | ||
threshold: 0.5 // Trigger callback when 50% of the element is visible | ||
}; | ||
|
||
// Create an Intersection Observer instance | ||
const observer = new IntersectionObserver(dabHandleIntersection, dabOptions); | ||
|
||
// Array of div IDs to track | ||
var dynamicAdBoostAdUnits = {}; | ||
var dabStartDate = new Date(); | ||
var dabStartTime = dabStartDate.getTime(); | ||
|
||
function init(config, userConsent) { | ||
if (config.params.keyId) { | ||
let keyId = config.params.keyId; | ||
if (keyId && !isEmptyStr(keyId)) { | ||
let dabDivIdsToTrack = config.params.adUnits; | ||
var dabInterval = setInterval(function() { | ||
// Observe each div by its ID | ||
dabDivIdsToTrack.forEach(divId => { | ||
let div = document.getElementById(divId); | ||
if (div) { | ||
observer.observe(div); | ||
} | ||
}); | ||
|
||
var dabDateNow = new Date(); | ||
var dabTimeNow = dabDateNow.getTime(); | ||
var dabElapsedSeconds = Math.floor((dabTimeNow - dabStartTime) / 1000); | ||
let elapsedThreshold = 30; | ||
if (config.params.threshold) { | ||
elapsedThreshold = config.params.threshold; | ||
} | ||
if (dabElapsedSeconds >= elapsedThreshold) { | ||
clearInterval(dabInterval); // Stop | ||
loadLmScript(keyId); | ||
} | ||
}, 1000); | ||
|
||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function loadLmScript(keyId) { | ||
let viewableAdUnits = Object.keys(dynamicAdBoostAdUnits); | ||
let viewableAdUnitsCSV = viewableAdUnits.join(','); | ||
const scriptUrl = `${SCRIPT_URL}/${keyId}.js?viewableAdUnits=${viewableAdUnitsCSV}`; | ||
loadExternalScript(scriptUrl, MODULE_NAME); | ||
} | ||
|
||
function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { | ||
const reqAdUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; | ||
|
||
if (Array.isArray(reqAdUnits)) { | ||
reqAdUnits.forEach(adunit => { | ||
let gptCode = deepAccess(adunit, 'code'); | ||
if (dynamicAdBoostAdUnits.hasOwnProperty(gptCode)) { | ||
// AdUnits has reached target viewablity at some point | ||
deepSetValue(adunit, `ortb2Imp.ext.data.${MODULE_NAME}.${gptCode}`, dynamicAdBoostAdUnits[gptCode]); | ||
} | ||
}); | ||
} | ||
callback(); | ||
} | ||
|
||
// Callback function when an observed element becomes visible | ||
function dabHandleIntersection(entries) { | ||
entries.forEach(entry => { | ||
if (entry.isIntersecting && entry.intersectionRatio > 0.5) { | ||
dynamicAdBoostAdUnits[entry.target.id] = entry.intersectionRatio; | ||
} | ||
}); | ||
} | ||
|
||
/** @type {RtdSubmodule} */ | ||
export const subModuleObj = { | ||
name: MODULE_NAME, | ||
init, | ||
getBidRequestData | ||
}; | ||
|
||
submodule('realTimeData', subModuleObj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Overview | ||
|
||
Module Name: Dynamic Ad Boost | ||
Module Type: Track when a adunit is viewable | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
Enhance your revenue with the cutting-edge DynamicAdBoost module! By seamlessly integrating the powerful LuponMedia technology, our module retrieves adunits viewability data, providing publishers with valuable insights to optimize their revenue streams. To unlock the full potential of this technology, we provide a customized LuponMedia module tailored to your specific site requirements. Boost your ad revenue and gain unprecedented visibility into your performance with our advanced solution. | ||
|
||
In order to utilize this module, it is essential to collaborate with [LuponMedia](https://www.luponmedia.com/) to create an account and obtain detailed guidelines on configuring your sites. Working hand in hand with LuponMedia will ensure a smooth integration process, enabling you to fully leverage the capabilities of this module on your website. Take the first step towards optimizing your ad revenue and enhancing your site's performance by partnering with LuponMedia for a seamless experience. | ||
Contact [email protected] for information. | ||
|
||
## Building Prebid with Real-time Data Support | ||
|
||
First, make sure to add the Dynamic AdBoost submodule to your Prebid.js package with: | ||
|
||
`gulp build --modules=rtdModule,dynamicAdBoostRtdProvider` | ||
|
||
The following configuration parameters are available: | ||
|
||
``` | ||
pbjs.setConfig( | ||
... | ||
realTimeData: { | ||
auctionDelay: 2000, | ||
dataProviders: [ | ||
{ | ||
name: "dynamicAdBoost", | ||
params: { | ||
keyId: "[PROVIDED_KEY]", // Your provided Dynamic AdBoost keyId | ||
adUnits: ["allowedAdUnit1", "allowedAdUnit2"], | ||
threshold: 35 // optional | ||
} | ||
} | ||
] | ||
} | ||
... | ||
} | ||
``` |