Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TargetVideo AdServer: add emqsegs support #12369

Closed
Closed
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
13 changes: 13 additions & 0 deletions modules/targetVideoAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function buildVideoUrl(options) {
const adUnit = options.adUnit;
const bid = options.bid || targeting.getWinningBids(adUnit.code)[0];
const allTargetingData = getAllTargetingData(options);
const emqsegs = getEmetriqSegments();
const custParams = options.params.cust_params;
let iu = options.params.iu;

Expand All @@ -58,6 +59,10 @@ export function buildVideoUrl(options) {
urlComponents.search.cust_params = Object.entries(custParams).map(([key, value]) => key + '%3D' + value).join('%26');
}

if (emqsegs) {
urlComponents.search.emqsegs = emqsegs;
}

return buildUrl(urlComponents);
}

Expand All @@ -72,6 +77,10 @@ export function buildVideoUrl(options) {
search.cust_params = Object.entries(custParams).map(([key, value]) => key + '%3D' + value).join('%26');
}

if (emqsegs) {
search.emqsegs = emqsegs;
}

return buildUrl({
protocol: 'https',
host: 'vid.tvserve.io',
Expand All @@ -91,6 +100,10 @@ function getAllTargetingData(options) {
return allTargetingData;
}

function getEmetriqSegments() {
return window?._emqsegs;
}

registerVideoSupport('targetVideo', {
buildVideoUrl,
});
48 changes: 48 additions & 0 deletions test/spec/modules/targetVideoAdServerVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ describe('TargetVideo Ad Server Video', function() {
},
};
adUnit = utils.deepClone(AD_UNIT);
window._emqsegs = null;
});

afterEach(() => {
sandbox.restore();
window._emqsegs = null;
});

it('should return undefined if required properties are missing', () => {
Expand Down Expand Up @@ -176,4 +178,50 @@ describe('TargetVideo Ad Server Video', function() {
getWinningBidsStub.restore();
getAllTargetingDataStub.restore();
});

it('should include emqsegs parameter when window._emqsegs is present', () => {
const optionsUrl = {
params: { ...unitUrl }
};

const optionsId = {
params: { ...unitId }
};

window._emqsegs = '1,2,3,4,5';

const getWinningBidsStub = sandbox.stub(targeting, 'getWinningBids').returns([bid]);
const getAllTargetingDataStub = sandbox.stub(targeting, 'getAllTargeting').returns(allTargeting);

const url1 = buildVideoUrl(Object.assign(optionsUrl, { bid, adUnit }));
const url2 = buildVideoUrl(Object.assign(optionsId, { bid, adUnit }));

expect(url1).to.include('emqsegs=1,2,3,4,5');
expect(url2).to.include('emqsegs=1,2,3,4,5');

getWinningBidsStub.restore();
getAllTargetingDataStub.restore();
});

it('should not include emqsegs parameter when window._emqsegs is not present', () => {
const optionsUrl = {
params: { ...unitUrl }
};

const optionsId = {
params: { ...unitId }
};

const getWinningBidsStub = sandbox.stub(targeting, 'getWinningBids').returns([bid]);
const getAllTargetingDataStub = sandbox.stub(targeting, 'getAllTargeting').returns(allTargeting);

const url1 = buildVideoUrl(Object.assign(optionsUrl, { bid, adUnit }));
const url2 = buildVideoUrl(Object.assign(optionsId, { bid, adUnit }));

expect(url1).to.not.include('emqsegs');
expect(url2).to.not.include('emqsegs');

getWinningBidsStub.restore();
getAllTargetingDataStub.restore();
});
});