@financial-times/o-ads
Advanced tools
Comparing version 18.0.0-beta to 18.0.0-beta2
@@ -14,2 +14,4 @@ "use strict"; | ||
var _api = _interopRequireDefault(require("./dist/js/data-providers/api")); | ||
var _moat = _interopRequireDefault(require("./dist/js/data-providers/moat")); | ||
@@ -42,2 +44,3 @@ | ||
Ads.prototype.gpt = _gpt.default; | ||
Ads.prototype.api = _api.default; | ||
Ads.prototype.moat = _moat.default; | ||
@@ -75,28 +78,38 @@ Ads.prototype.targeting = _targeting.default; | ||
this.utils.broadcast('initialising'); | ||
this.targeting.add(this.config().targeting); | ||
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 the source of the ad | ||
traffic is legit before we initialise the library. | ||
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 | ||
*/ | ||
if (this.config().validateAdsTraffic) { | ||
return this.moat.init().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 checking for invalid traffic via MOAT script. Loading the o-ads library anyway, but the ads may not work as expected...'); | ||
return this.initLibrary(); | ||
}); | ||
} | ||
return Promise.resolve(this.initLibrary()); | ||
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(); | ||
}); | ||
}; | ||
/** | ||
* Update page level targeting data in o-ads and GPT | ||
*/ | ||
Ads.prototype.updateContext = function (options) { | ||
this.config(options); | ||
Ads.prototype.updateTargeting = function (data) { | ||
this.targeting.add(data); | ||
this.gpt.updatePageTargeting(this.targeting.get()); | ||
if (options.targetingApi) { | ||
this.api.reset(); | ||
return this.api.init(options.targetingApi, this).then(() => { | ||
this.gpt.updatePageTargeting(this.targeting.get()); | ||
}); | ||
} else { | ||
return Promise.resolve(); | ||
} | ||
}; | ||
@@ -103,0 +116,0 @@ |
@@ -26,3 +26,3 @@ "use strict"; | ||
_utils.default.extend(parameters, this.socialFlow(), this.getVersion()); | ||
_utils.default.extend(parameters, this.getFromConfig(), this.socialFlow(), this.getVersion()); | ||
@@ -56,3 +56,21 @@ 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 () { | ||
@@ -59,0 +77,0 @@ if ((0, _config.default)('passOAdsVersion')) { |
@@ -13,2 +13,3 @@ /* eslint no-console: 0 */ | ||
const path = require('path'); | ||
const BowerResolvePlugin = require('bower-resolve-webpack-plugin'); | ||
@@ -65,2 +66,42 @@ | ||
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 | ||
@@ -67,0 +108,0 @@ |
@@ -74,2 +74,4 @@ { | ||
"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", | ||
@@ -133,2 +135,4 @@ "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", | ||
@@ -135,0 +139,0 @@ "name": "leaderboard", |
@@ -28,4 +28,5 @@ { | ||
"name": "@financial-times/o-ads", | ||
"version": "18.0.0-beta", | ||
"version": "18.0.0-beta2", | ||
"dependencies": { | ||
"ftdomdelegate": "^4.0.0", | ||
"@financial-times/o-viewport": "^4.0.0", | ||
@@ -46,3 +47,3 @@ "@financial-times/o-grid": "^5.0.0", | ||
"test-coverage": "karma start karma.conf.js --single-run", | ||
"test-unit": "jest && npm run test-coverage", | ||
"test-unit": "jest", | ||
"test-cy:run": "cypress run -r spec --record false", | ||
@@ -105,3 +106,3 @@ "test-cy:open": "cypress open", | ||
"nightwatch": "git@github.com:Financial-Times/nightwatch.git", | ||
"origami-build-tools": "^9.0.13", | ||
"origami-build-tools": "^8.0.0", | ||
"pre-git": "^3.17.1", | ||
@@ -108,0 +109,0 @@ "puppeteer": "^1.19.0", |
@@ -10,27 +10,16 @@ # @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)** | ||
**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)** | ||
**[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 | ||
@@ -107,2 +96,3 @@ 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** | ||
@@ -113,2 +103,3 @@ - `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. | ||
@@ -122,4 +113,8 @@ - `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]() | ||
- `targeting` *(optional)* `<Object>` - An object of key => value pairs that will be appended to every ad call on the page | ||
- `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. | ||
@@ -237,13 +232,11 @@ | ||
## Page level targeting | ||
## Ads-api (global) | ||
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 | ||
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: | ||
```javascript | ||
oAds.init({ | ||
... | ||
targeting: { | ||
key: "value", | ||
key2: "value2", | ||
... | ||
targetingApi: { | ||
user: "https://ads-api.ft.com/v1/user", | ||
page: "https://ads-api.ft.com/v1/content/<content-id>" | ||
}, | ||
@@ -254,4 +247,14 @@ ... | ||
## Ad slot level targeting | ||
## dfp_targeting (global) | ||
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: | ||
@@ -338,6 +341,9 @@ | ||
## `oAds.initialising` | ||
Triggered when the library starts the initialisation process. | ||
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. | ||
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` | ||
@@ -344,0 +350,0 @@ 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. |
@@ -14,2 +14,3 @@ import config from './config'; | ||
parameters, | ||
this.getFromConfig(), | ||
this.socialFlow(), | ||
@@ -45,3 +46,18 @@ 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() { | ||
@@ -48,0 +64,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
230724
49
5989
504
5
3
4
+ Addedftdomdelegate@^4.0.0
+ Addedftdomdelegate@4.0.6(transitive)