@financial-times/ads-display
Advanced tools
Comparing version
@@ -257,2 +257,8 @@ import { getRootID } from '@financial-times/o-tracking/dist/javascript/core.js'; | ||
const oAdsInstance = await displayAds.initOads(options, flags); | ||
if (options.waitForMoat) { | ||
return waitForMoat(1000) | ||
.finally(() => displayAds.initAdSlots(oAdsInstance)) | ||
} | ||
displayAds.initAdSlots(oAdsInstance); | ||
@@ -496,2 +502,18 @@ } | ||
function waitForMoat (timeout) { | ||
return new Promise((resolve, reject) => { | ||
const checkMoatInterval = setInterval(() => { | ||
if(window.moatPrebidApi && window.moatPrebidApi.safetyDataAvailable()) { | ||
clearInterval(checkMoatInterval); | ||
clearTimeout(timeoutId); | ||
resolve(); | ||
} | ||
}, 50); | ||
const timeoutId = setTimeout(() => { | ||
clearInterval(checkMoatInterval); | ||
reject(); | ||
}, timeout); | ||
}); | ||
} | ||
// Necessary for testing | ||
@@ -509,3 +531,4 @@ const displayAds = { | ||
getGptZone, | ||
validateTraffic | ||
validateTraffic, | ||
waitForMoat | ||
}; | ||
@@ -512,0 +535,0 @@ |
{ | ||
"name": "@financial-times/ads-display", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Bring ads to your page with the FT specific o-ads configuration", | ||
@@ -13,3 +13,6 @@ "browser": "dist/client.js", | ||
"dev": "NODE_ENV=development rollup -c rollup.config.dev.js --watch", | ||
"build": "npm run clean && rollup -c" | ||
"build": "npm run clean && rollup -c", | ||
"certs": "source ./scripts/demo.sh && certs", | ||
"demo": "source ./scripts/demo.sh && demo", | ||
"demo-https": "source ./scripts/demo.sh && demo_https" | ||
}, | ||
@@ -39,3 +42,3 @@ "lint-staged": { | ||
"dependencies": { | ||
"@financial-times/ads-permutive": "^0.3.1", | ||
"@financial-times/ads-permutive": "^0.4.0", | ||
"@financial-times/n-tracking": "^1.3.1", | ||
@@ -61,3 +64,3 @@ "@financial-times/o-ads": "18.3.3", | ||
"react-dom": "^16.8.6", | ||
"regenerator-runtime": "^0.13.5", | ||
"regenerator-runtime": "^0.13.7", | ||
"rollup": "^2.0.0", | ||
@@ -64,0 +67,0 @@ "rollup-plugin-babel": "^4.3.3", |
@@ -273,2 +273,3 @@ # @financial-times/ads-display [](https://circleci.com/gh/Financial-Times/ads-display/tree/master) | ||
} | ||
- `waitForMoat`: *(optional)* `<Boolean>` - Will wait 1 second max for the moat prebid api to be loaded before initialising any ad slot so that we can get invalid traffic data with the ad requests | ||
``` | ||
@@ -334,6 +335,9 @@ | ||
### `displayAds.validateTraffic()` | ||
### `displayAds.validateTraffic(callback: function, deferScript: boolean)` | ||
Check weather the request is deemed as valid traffic (using an external script from moat). Talks directly to the global `window.googletag` object to set an extra targeting parameter `m_data` = `0` (valid) or `1` (invalid) for every ad call. Filtering of ads is done on the Google Ad Manager side based on these targeting parameters. There is a race condition between `displayAds.validateTraffic()` and `displayAds.init()` so the first ad call may not have the right value for the `m_data` parameter. | ||
- `callback`: Called when the moat script is loaded | ||
- `deferScript`: Defer loading of the moat script, true by default | ||
## `adsUtils` | ||
@@ -340,0 +344,0 @@ |
50978
2.2%888
2.3%473
0.85%+ Added
- Removed