@financial-times/o-ads
Advanced tools
Comparing version 18.0.0-beta2 to 18.0.0-beta3
@@ -14,6 +14,2 @@ "use strict"; | ||
var _api = _interopRequireDefault(require("./dist/js/data-providers/api")); | ||
var _moat = _interopRequireDefault(require("./dist/js/data-providers/moat")); | ||
var _targeting = _interopRequireDefault(require("./dist/js/targeting")); | ||
@@ -44,4 +40,2 @@ | ||
Ads.prototype.gpt = _gpt.default; | ||
Ads.prototype.api = _api.default; | ||
Ads.prototype.moat = _moat.default; | ||
Ads.prototype.targeting = _targeting.default; | ||
@@ -78,38 +72,14 @@ Ads.prototype.utils = _utils.default; | ||
var targetingApi = this.config().targetingApi; | ||
var validateAdsTraffic = this.config().validateAdsTraffic; | ||
this.utils.broadcast('initialising'); // Don't need to fetch anything if no targeting or validateAdsTraffic configured. | ||
if (!targetingApi && !validateAdsTraffic) { | ||
return Promise.resolve(this.initLibrary()); | ||
} | ||
var targetingPromise = targetingApi ? this.api.init(targetingApi, this) : Promise.resolve(); | ||
var validateAdsTrafficPromise = validateAdsTraffic ? this.moat.init() : Promise.resolve(); | ||
/** | ||
Need to wait for the moat script to load to validate ads | ||
and the targeting API to return before we initialise the library. | ||
The targeting values are set on the instance of this.api, therefore | ||
response is irrelevant | ||
*/ | ||
return Promise.all([targetingPromise, validateAdsTrafficPromise]).then(() => this.initLibrary()).catch(e => { | ||
// If anything fails, default to load ads without targeting | ||
this.utils.log.error(e); | ||
this.utils.log.warn('There was an error with the targeting API or the Moat invalid traffic script. Loading the o-ads library anyway, but the ads may not work as expected...'); | ||
return this.initLibrary(); | ||
}); | ||
this.utils.broadcast('initialising'); | ||
this.targeting.add(this.config().targeting); | ||
return Promise.resolve(this.initLibrary()); | ||
}; | ||
/** | ||
* Update page level targeting data in o-ads and GPT | ||
*/ | ||
Ads.prototype.updateContext = function (options) { | ||
this.config(options); | ||
if (options.targetingApi) { | ||
this.api.reset(); | ||
return this.api.init(options.targetingApi, this).then(() => { | ||
this.gpt.updatePageTargeting(this.targeting.get()); | ||
}); | ||
} else { | ||
return Promise.resolve(); | ||
} | ||
Ads.prototype.updateTargeting = function (data) { | ||
this.targeting.add(data); | ||
this.gpt.updatePageTargeting(this.targeting.get()); | ||
}; | ||
@@ -116,0 +86,0 @@ |
@@ -26,3 +26,3 @@ "use strict"; | ||
_utils.default.extend(parameters, this.getFromConfig(), this.socialFlow(), this.getVersion()); | ||
_utils.default.extend(parameters, this.socialFlow(), this.getVersion()); | ||
@@ -56,21 +56,3 @@ for (var item in methods) { | ||
}; | ||
/** | ||
* getFromConfig returns an object containing all the key values pairs specified in the dfp_targeting | ||
* config. | ||
*/ | ||
Targeting.prototype.getFromConfig = function () { | ||
var targeting = (0, _config.default)('dfp_targeting') || {}; | ||
if (!_utils.default.isPlainObject(targeting)) { | ||
/* istanbul ignore else */ | ||
if (_utils.default.isString(targeting)) { | ||
targeting = _utils.default.hash(targeting, ';', '='); | ||
} | ||
} | ||
return targeting; | ||
}; | ||
Targeting.prototype.getVersion = function () { | ||
@@ -77,0 +59,0 @@ if ((0, _config.default)('passOAdsVersion')) { |
@@ -13,3 +13,2 @@ /* eslint no-console: 0 */ | ||
const path = require('path'); | ||
const BowerResolvePlugin = require('bower-resolve-webpack-plugin'); | ||
@@ -66,42 +65,2 @@ | ||
if (process.env.COVERAGE) { | ||
console.log('running coverage report'); | ||
options.files.push({ pattern: 'reports/**', included: false, watched: false }); | ||
options.reporters.push('coverage-istanbul'); | ||
options.coverageIstanbulReporter = { | ||
dir: 'reports/coverage/', | ||
reports: ['html', 'text', 'json'], | ||
thresholds: { | ||
emitWarning: false, | ||
global: { | ||
statements: 98, | ||
branches: 95, | ||
functions: 81, | ||
lines: 98 | ||
}, | ||
each: { | ||
statements: 75, | ||
branches: 70, | ||
functions: 81, | ||
lines: 75 | ||
} | ||
}, | ||
fixWebpackSourcePaths: true | ||
}; | ||
options.webpack.module = { | ||
rules: [ | ||
// instrument only testing sources with Istanbul | ||
{ | ||
test: /\.js$/, | ||
use: { | ||
loader: 'istanbul-instrumenter-loader', | ||
options: { esModules: true } | ||
}, | ||
enforce: 'post', | ||
include: path.resolve('src/js/'), | ||
} | ||
] | ||
}; | ||
} | ||
if (process.env.CIRCLECI) { } // eslint-disable-line no-empty | ||
@@ -108,0 +67,0 @@ |
@@ -74,4 +74,2 @@ { | ||
"data": { | ||
"user": "https://ads-api.ft.com/v1/user", | ||
"page": "https://ads-api.ft.com/v1/content/047b1294-75a9-11e6-b60a-de4532d5ea35", | ||
"class": "o--if-nojs o-ads o-ads--background o-ads--center o-ads--reserve-90 o-ads--transition", | ||
@@ -135,4 +133,2 @@ "name": "billboard", | ||
"data": { | ||
"user": "https://ads-api.ft.com/v1/user", | ||
"page": "https://ads-api.ft.com/v1/content/047b1294-75a9-11e6-b60a-de4532d5ea35", | ||
"class": "o--if-nojs o-ads o-ads--background o-ads--center o-ads--reserve-90 o-ads--transition", | ||
@@ -139,0 +135,0 @@ "name": "leaderboard", |
@@ -28,5 +28,4 @@ { | ||
"name": "@financial-times/o-ads", | ||
"version": "18.0.0-beta2", | ||
"version": "18.0.0-beta3", | ||
"dependencies": { | ||
"ftdomdelegate": "^4.0.0", | ||
"@financial-times/o-viewport": "^4.0.0", | ||
@@ -47,3 +46,3 @@ "@financial-times/o-grid": "^5.0.0", | ||
"test-coverage": "karma start karma.conf.js --single-run", | ||
"test-unit": "jest", | ||
"test-unit": "jest && npm run test-coverage", | ||
"test-cy:run": "cypress run -r spec --record false", | ||
@@ -106,3 +105,3 @@ "test-cy:open": "cypress open", | ||
"nightwatch": "git@github.com:Financial-Times/nightwatch.git", | ||
"origami-build-tools": "^8.0.0", | ||
"origami-build-tools": "^9.0.13", | ||
"pre-git": "^3.17.1", | ||
@@ -109,0 +108,0 @@ "puppeteer": "^1.19.0", |
100
README.md
@@ -10,16 +10,27 @@ # @financial-times/o-ads [![CircleCI](https://circleci.com/gh/Financial-Times/o-ads/tree/master.svg?style=svg&circle-token=ff0caeb981693cbbbab6b70ab0ac99c9314bfc4f)](https://circleci.com/gh/Financial-Times/o-ads/tree/master) | ||
# Table of Contents | ||
**1. [Install](#install)** | ||
**2. [Setup & Configuration](#setup-config)** | ||
**3. [Define Ad Slots](#define-ad-slots)** | ||
**4. [Targeting](#targeting)** | ||
**5. [Lazy Loading](#lazy-loading)** | ||
**6. [Invalid Traffic](#invalid-traffic)** | ||
**7. [Styling](#styling)** | ||
**8. [Events](#events)** | ||
**9. [Metrics & Monitoring](#metrics--monitoring)** | ||
**10. [Misc](#misc)** | ||
**11. [Developing](#developing)** | ||
**12. [Migration](https://github.com/financial-times/o-ads/blob/master/MIGRATION.md)** | ||
**[1. Install](#install)** | ||
**[2. Setup & Configuration](#setup-config)** | ||
**[3. Define Ad Slots](#define-ad-slots)** | ||
**[4. Targeting](#targeting)** | ||
**[5. Lazy Loading](#lazy-loading)** | ||
**[6. Invalid Traffic](#invalid-traffic)** | ||
**[7. Styling](#styling)** | ||
**[8. Events](#events)** | ||
**[9. Metrics & Monitoring](#metrics--monitoring)** | ||
**[10. Misc](#misc)** | ||
**[11. Developing](#developing)** | ||
**[12. Migration](https://github.com/financial-times/o-ads/blob/master/MIGRATION.md)** | ||
# Install | ||
@@ -96,3 +107,2 @@ Step One. You need to include the o-ads library on your site. There are two ways: | ||
- `gpt.zone` *(optional)* `<String>` | ||
- `behavioralMeta` *(deprecated)* `<Object>` - Behavioural data set by the ads-api. **DO NOT USE** | ||
- `canonical` *(deprecated)* `<String>` - Overwrite the GPT *page_url* parameter **DO NOT USE** | ||
@@ -103,3 +113,2 @@ - `collapseEmpty` *(optional)* `<String> "before" | "after" | "never"` - How should the slot be collapsed if there is no ad to be shown | ||
- `"never"` - The ad slot never collapses, even if no ad is found. | ||
- `dfp_targeting` *(optional)* `<String>` - Set targeting parameters for google ad manager | ||
- `disableConsentCookie` *(optional)* `<Boolean>` - o-ads looks for consent in the FTConsent cookie. Set to false to disable this. | ||
@@ -113,11 +122,5 @@ - `flags` *(deprecated)* `<Object>` - Flags object. **DO NOT USE** | ||
- `responsive` *(optional)* `<Object>` - Overwrite the default breakpoints. See [breakpoints](#breakpoints) | ||
- `refresh` *(deprecated)* `<Boolean>` - **DO NOT USE**. This is an old flag that is not used any more. | ||
- `slots` *(deprecated)* `<Object>` - Old way of defining slots. See [Defining an Ad Slots]() | ||
- `targetingApi` *(optional)* `<Object>` - API to call for targeting information | ||
- `targetingApi.user` *(optional)* `<String>` - API endpoint for user related data | ||
- `targetingApi.page` *(optional)* `<String>` - API endpoint for page related data | ||
- `targetingApi.usePageZone` *(optional)* `<Boolean>` - Overwrite the `gpt.zone` config setting with a response from the targeting API | ||
- `validateAdsTraffic` *(optional)* `<Boolean>` - Validate the user is not a bot before making ad calls. This uses the [Moat](https://moat.com/) service. | ||
- `targeting` *(optional)* `<Object>` - An object of key => value pairs that will be appended to every ad call on the page | ||
# Define Ad Slots | ||
@@ -232,11 +235,13 @@ | ||
## Ads-api (global) | ||
## Page level targeting | ||
The [ads-api](https://github.com/financial-times/ads-api) is an api that aggregates information from various sources and returns it in a format that o-ads can use and append to every ad call. This can be configured when initialising o-ads like so: | ||
You can specify an object of key => value pairs when initialising o-ads. Each key => value pair will be appended to every ad request on the page | ||
```javascript | ||
oAds.init({ | ||
... | ||
targetingApi: { | ||
user: "https://ads-api.ft.com/v1/user", | ||
page: "https://ads-api.ft.com/v1/content/<content-id>" | ||
targeting: { | ||
key: "value", | ||
key2: "value2", | ||
... | ||
}, | ||
@@ -247,14 +252,4 @@ ... | ||
## dfp_targeting (global) | ||
## Ad slot level targeting | ||
When configuring o-ads, you can specificy a string of targeting parameters seperated by a semicolon. These will be added to every ad call. | ||
```javascript | ||
oAds.init({ | ||
... | ||
dfp_targeting: "pos=top;version=1;test=yes" | ||
... | ||
}); | ||
``` | ||
## Ad slot targeting (ad slot specific) | ||
You can also specify targeting parameters for any particular ad slot, by using the `data-o-ads-targeting` attribute when defining the ad slot: | ||
@@ -299,21 +294,2 @@ | ||
# Invalid Traffic | ||
The library provide the option to check for invalid traffic before serving an ad. This relies on a third party script from Moat which you must include on your page, preferrably in the <head> section on your page | ||
```javascript | ||
<script async id="moat-ivt" src="https://sejs.moatads.com/financialtimesprebidheader859796398452/yi.js"></script> | ||
``` | ||
This script will append the `m_data` parameter to the ad call, with a value of 0 or 1. DFP will then use this parameter to decide whether to serve an ad or not. | ||
To enable this feature make sure you have the script above on your page and enable the following config setting when initialising o-ads: | ||
```javascript | ||
oAds.init({ | ||
... | ||
validateAdsTraffic: true, | ||
... | ||
}); | ||
``` | ||
# Styling | ||
@@ -342,12 +318,4 @@ | ||
## `oAds.initialising` | ||
Triggered when the library starts the initialisation process. At this point in time, if targetingApi has been defined in the configuration, two separate calls are made to the targeting api in order to get ‘user’ and ‘page’ targeting parameters. | ||
Triggered when the library starts the initialisation process. | ||
Also at this point, if validateAdsTraffic is set to true, o-ads will check if the traffic validation script (currently moat.js) is available and use it to check if the traffic source is a valid one. | ||
## `oAds.adsAPIComplete` | ||
If targeting has been configured, this event is triggered when both requests to the targeting api (‘user’ and ‘page’) have been fullfilled (whether successfully or not). | ||
## `oAds.IVTComplete` | ||
If validateAdsTraffic is set to true, this event is triggered as soon as the traffic has been validated or, if the traffic validation script can’t been found, when the associated timeout period expires. | ||
## `oAds.initialised` | ||
@@ -386,3 +354,3 @@ Triggered when the library has been initialised and the config has been set. (Note: the GPT library may not have been loaded by this point). | ||
Firstly, o-ads saves a [performance mark](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark) every time it dispatches one of the many [events](#events) that indicate a milestone in the ads loading process. The [Performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance) used for this is native browser functionality that provides high resolution time measurements. | ||
Firstly, o-ads saves a [performance mark](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark) every time it dispatches one of the many [events](#events) that indicate a milestone in the ads loading process. If used from [n-ads](https://github.com/Financial-Times/n-ads), extra performance marks might be added. See the [n-ads docs](https://github.com/Financial-Times/n-ads#monitoring) | ||
@@ -389,0 +357,0 @@ ## `oAds.utils.setupMetrics()` |
@@ -14,3 +14,2 @@ import config from './config'; | ||
parameters, | ||
this.getFromConfig(), | ||
this.socialFlow(), | ||
@@ -46,18 +45,3 @@ this.getVersion() | ||
/** | ||
* getFromConfig returns an object containing all the key values pairs specified in the dfp_targeting | ||
* config. | ||
*/ | ||
Targeting.prototype.getFromConfig = function() { | ||
let targeting = config('dfp_targeting') || {}; | ||
if (!utils.isPlainObject(targeting)) { | ||
/* istanbul ignore else */ | ||
if (utils.isString(targeting)) { | ||
targeting = utils.hash(targeting, ';', '='); | ||
} | ||
} | ||
return targeting; | ||
}; | ||
Targeting.prototype.getVersion = function() { | ||
@@ -64,0 +48,0 @@ if (config('passOAdsVersion')) { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
4
2
0
216328
45
5657
472
- Removedftdomdelegate@^4.0.0
- Removedftdomdelegate@4.0.6(transitive)