Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

make tracking and ads resilient to changing concept id to v2 #932

Merged
merged 2 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/n-ui/ads/js/oAdsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ module.exports = function (flags, appName, adOptions) {
let url;
const apiUrlRoot = 'https://ads-api.ft.com/v1/';
if (appName === 'article') {
uuid = document.querySelector('[data-content-id]').getAttribute('data-content-id');
uuid = document.documentElement.getAttribute('data-content-id');

const referrer = utils.getReferrer();
url = `${apiUrlRoot}content/${uuid}`;
if(referrer) {
url += `?referrer=${encodeURIComponent(referrer.split(/[?#]/)[0])}`;
}
} else if (appName === 'stream-page') {
uuid = document.querySelector('[data-concept-id]').getAttribute('data-concept-id');
uuid = document.documentElement.getAttribute('data-concept-idv1') || document.documentElement.getAttribute('data-concept-id');
url = `${apiUrlRoot}concept/${uuid}`;
}

Expand Down
191 changes: 104 additions & 87 deletions components/n-ui/ads/test/oAdsConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const utils = require('../js/utils');
const oAdsConfig = require('../js/oAdsConfig');
const adsSandbox = require('../js/sandbox');
const fakeArticleUuid = '123456';
const fakeConceptUuidV1 = '1234567';
const fakeConceptUuid = '12345678';

let sandbox;
let targeting;
Expand All @@ -15,120 +17,135 @@ describe('Config', () => {

sandbox.stub(utils, 'getLayoutName', () => { return 'custom'; });
sandbox.stub(utils, 'getReferrer', () => null );

targeting = sandbox.stub(document, 'querySelector');
targeting.withArgs('[data-concept-id]').returns({getAttribute: () => fakeArticleUuid});
targeting.withArgs('[data-content-id]').returns({getAttribute: () => fakeArticleUuid});
targeting = sandbox.stub(document.documentElement, 'getAttribute');
targeting.withArgs('data-content-id').returns(fakeArticleUuid);
});

afterEach(() => {
sandbox.restore();
});

describe('third party', () => {
it('Should set gpt configuration value according to app name', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', false);
const gptAttributes = {
network: '5887',
site: 'ft.com',
zone: 'unclassified'
}

it('Should set gpt configuration value according to app name', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', false);
const gptAttributes = {
network: '5887',
site: 'ft.com',
zone: 'unclassified'
}
expect(config.gpt).to.deep.equal(gptAttributes);
});

expect(config.gpt).to.deep.equal(gptAttributes);
});
it('Should set gpt configuration value according to app name and sandbox', () => {
const flags = { get: () => true };
sandbox.stub(adsSandbox, 'isActive', () => { return true; });
const config = oAdsConfig(flags, 'article');
const gptAttributes = {
network: '5887',
site: 'sandbox.next.ft',
zone: 'unclassified'
}
expect(config.gpt).to.deep.equal(gptAttributes);
});

it('Should set gpt configuration value according to app name and sandbox', () => {
const flags = { get: () => true };
sandbox.stub(adsSandbox, 'isActive', () => { return true; });
const config = oAdsConfig(flags, 'article');
const gptAttributes = {
network: '5887',
site: 'sandbox.next.ft',
zone: 'unclassified'
}
expect(config.gpt).to.deep.equal(gptAttributes);
});

it('Should set krux configuration when flag is set to false', () => {
const flags = { get: () => true };
document.cookie = 'FT_U=EID=1234_PID=abc';
const config = oAdsConfig(flags, 'article' );
const userExpectation = {
eid: '1234'
};

it('Should set krux configuration when flag is set to false', () => {
const flags = { get: () => true };
document.cookie = 'FT_U=EID=1234_PID=abc';
const config = oAdsConfig(flags, 'article' );
const userExpectation = {
eid: '1234'
};
expect(config.krux.id).to.be.ok;
expect(config.krux.attributes).to.be.ok;
expect(config.krux.attributes.user).to.be.ok;
expect(config.krux.attributes.user).to.deep.equal(userExpectation);
});

expect(config.krux.id).to.be.ok;
expect(config.krux.attributes).to.be.ok;
expect(config.krux.attributes.user).to.be.ok;
expect(config.krux.attributes.user).to.deep.equal(userExpectation);
});
it('Should not set krux configuration when flag is set to false', () => {
const flags = { get: (param) => param === 'krux' ? false : true };
const config = oAdsConfig(flags, 'article' );

it('Should not set krux configuration when flag is set to false', () => {
const flags = { get: (param) => param === 'krux' ? false : true };
const config = oAdsConfig(flags, 'article' );
expect(config.krux).to.be.false;
});

expect(config.krux).to.be.false;
});
it('Should not set krux configuration when app requests no targeting', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true } );

it('Should not set krux configuration when app requests no targeting', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true } );
expect(config.krux).to.be.false;
});
it('Should set dfp_targeting config', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
document.cookie = 'FT_U=EID=1234_PID=abc';
const expectation = 'pt=art;eid=1234;nlayout=custom'.split(';');

expect(config.krux).to.be.false;
});
it('Should set dfp_targeting config', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
document.cookie = 'FT_U=EID=1234_PID=abc';
const expectation = 'pt=art;eid=1234;nlayout=custom'.split(';');

expectation.forEach((value) => expect(config.dfp_targeting).to.contain(value));
});

expectation.forEach((value) => expect(config.dfp_targeting).to.contain(value));
});
it('Should use zone from metadata if present', () => {
sandbox.stub(utils, 'getMetaData', (param) => {
switch (param) {
case 'dfp_site':
return 'testDfpSite';
break;
case 'dfp_zone':
return 'testDfpZone';
break;
}
});

const flags = { get: () => true };
const config = oAdsConfig(flags, 'article');
expect(config.gpt.zone).to.equal('testDfpSite/testDfpZone');
});
})

it('Should pass the correct url to o-ads fetch', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
const userUrl = 'https://ads-api.ft.com/v1/user'
const pageUrl = 'https://ads-api.ft.com/v1/content/'
describe('o-ads', () => {

it('Should pass the correct url to o-ads fetch', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
const userUrl = 'https://ads-api.ft.com/v1/user'
const pageUrl = 'https://ads-api.ft.com/v1/content/'

expect(config.targetingApi.user).to.equal(userUrl);
expect(config.targetingApi.page).to.equal(pageUrl + fakeArticleUuid);
})

expect(config.targetingApi.user).to.equal(userUrl);
expect(config.targetingApi.page).to.equal(pageUrl + fakeArticleUuid);
})
it('Should not request API targeting if app says not to', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true });
expect(config.targetingApi).to.equal(null);
})

it('Should not request API targeting if app says not to', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true });
expect(config.targetingApi).to.equal(null);
})
it('Should access concept url to send to o-ads fetch', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'stream-page' );
const pageUrl = 'https://ads-api.ft.com/v1/concept/'

it('Should access v1 concept url to send to o-ads fetch if present', () => {
targeting.withArgs('data-concept-idv1').returns(fakeConceptUuidV1);
targeting.withArgs('data-concept-id').returns(fakeConceptUuid);

expect(config.targetingApi.page).to.equal(pageUrl + fakeArticleUuid);
});
const flags = { get: () => true };
const config = oAdsConfig(flags, 'stream-page' );
const pageUrl = 'https://ads-api.ft.com/v1/concept/'

it('Should use zone from metadata if present', () => {
sandbox.stub(utils, 'getMetaData', (param) => {
switch (param) {
case 'dfp_site':
return 'testDfpSite';
break;
case 'dfp_zone':
return 'testDfpZone';
break;
}
expect(config.targetingApi.page).to.equal(pageUrl + fakeConceptUuidV1);
});

const flags = { get: () => true };
const config = oAdsConfig(flags, 'article');
expect(config.gpt.zone).to.equal('testDfpSite/testDfpZone');
});
it('Should access v2 concept url to send to o-ads fetch if present', () => {
targeting.withArgs('data-concept-id').returns(fakeConceptUuid);

const flags = { get: () => true };
const config = oAdsConfig(flags, 'stream-page' );
const pageUrl = 'https://ads-api.ft.com/v1/concept/'

expect(config.targetingApi.page).to.equal(pageUrl + fakeConceptUuid);
});

})

});
3 changes: 2 additions & 1 deletion components/n-ui/tracking/ft/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ const oTrackingWrapper = {
context.rootContentId = contentId;
}

const conceptId = getRootData('concept-id');
const conceptId = getRootData('concept-idv1') || getRootData('concept-id');
if (conceptId) {
context.rootConceptId = conceptId;
context.rootConceptIdV1 = getRootData('concept-idv1');
context.rootTaxonomy = getRootData('taxonomy');
}

Expand Down