Skip to content

Commit

Permalink
Add support for user sync (#5142)
Browse files Browse the repository at this point in the history
* Support new aniview bid adapter

* Support new aniview bid adapter

* Support new aniview bid adapter

* Support new aniview bid adapter

* Fix Consent parameters

* Update aniviewBidAdapter.js

V3 support

* Update aniviewBidAdapter.js

* Update aniviewBidAdapter.js

Update refererInfo

* Update aniviewBidAdapter.js

Fix tabs and spaces

* Update aniviewBidAdapter.js

fixes

* Update aniviewBidAdapter.js

* Update aniviewBidAdapter.js

Add ccpa support

* Update aniviewBidAdapter.js

Typo

* Update aniviewBidAdapter.js

* Update aniviewBidAdapter.js

* Fix size and sample

Fixed sizes from playerSize
Updated md sample

* Fix tabs

* Fix sizes

* Recheck

* Add tgt parameter

* Update sample

* Add support for cookie sync + tests

* Add support for cookie sync + tests

* Add support for cookie sync + tests
  • Loading branch information
itaynave authored Apr 29, 2020
1 parent 79e9d75 commit 991ad56
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
66 changes: 63 additions & 3 deletions modules/aniviewBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function isBidRequestValid(bid) {

return true;
}

let irc = 0;
function buildRequests(validBidRequests, bidderRequest) {
let bidRequests = [];

Expand All @@ -66,6 +66,7 @@ function buildRequests(validBidRequests, bidderRequest) {
let size = sizes[j];
let playerWidth;
let playerHeight;

if (size && size.length == 2) {
playerWidth = size[0];
playerHeight = size[1];
Expand Down Expand Up @@ -102,6 +103,9 @@ function buildRequests(validBidRequests, bidderRequest) {
s2sParams.pbjs = 1;
s2sParams.tgt = 10;
s2sParams.s2s = '1';
s2sParams.irc = irc;
irc++;
s2sParams.wpm = 1;

if (bidderRequest && bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.gdprApplies) {
Expand Down Expand Up @@ -191,12 +195,68 @@ function interpretResponse(serverResponse, bidRequest) {
return bidResponses;
}

function getSyncData(xml, options) {
let ret = [];
if (xml) {
let ext = xml.getElementsByTagName('Extensions');
if (ext && ext.length > 0) {
ext = ext[0].getElementsByTagName('Extension');
if (ext && ext.length > 0) {
for (var i = 0; i < ext.length; i++) {
if (ext[i].getAttribute('type') == 'ANIVIEW') {
let syncs = ext[i].getElementsByTagName('AdServingSync');
if (syncs && syncs.length == 1) {
try {
let data = JSON.parse(syncs[0].textContent);
if (data && data.trackers && data.trackers.length) {
data = data.trackers;
for (var j = 0; j < data.length; j++) {
if (typeof data[j] === 'object' && typeof data[j].url === 'string' && data[j].e === 'inventory') {
if (data[j].t == 1 && options.pixelEnabled) {
ret.push({url: data[j].url, type: 'image'});
} else {
if (data[j].t == 3 && options.iframeEnabled) {
ret.push({url: data[j].url, type: 'iframe'});
}
}
}
}
}
} catch (e) {}
}
break;
}
}
}
}
}
return ret;
}

function getUserSyncs(syncOptions, serverResponses) {
if (serverResponses && serverResponses[0] && serverResponses[0].body) {
if (serverResponses.error) {
return [];
} else {
try {
let xmlStr = serverResponses[0].body;
let xml = new window.DOMParser().parseFromString(xmlStr, 'text/xml');
if (xml && xml.getElementsByTagName('parsererror').length == 0) {
let syncData = getSyncData(xml, syncOptions);
return syncData;
}
} catch (e) {}
}
}
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [VIDEO],
isBidRequestValid,
buildRequests,
interpretResponse
}
interpretResponse,
getUserSyncs
};

registerBidder(spec);
18 changes: 18 additions & 0 deletions test/spec/modules/aniviewBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,22 @@ describe('ANIVIEW Bid Adapter Test', function () {
expect(result.length).to.equal(0);
});
});

describe('getUserSyncs', function () {
it('Check get sync pixels from response', function () {
let pixelUrl = 'https://sync.pixel.url/sync';
let pixelEvent = 'inventory';
let pixelType = '3';
let pixelStr = '{"url":"' + pixelUrl + '", "e":"' + pixelEvent + '", "t":' + pixelType + '}';
let bidResponse = '<?xml version="1.0" encoding="UTF-8"?><VAST version="2.0"><Ad id="FORD"><InLine><AdSystem>FORD</AdSystem><AdTitle>FORD</AdTitle><Impression><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=impression]]></Impression><Creatives><Creative><Linear><Duration>00:00:15</Duration><TrackingEvents><Tracking event="start"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=start]]></Tracking><Tracking event="firstQuartile"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=firstQuartile]]></Tracking><Tracking event="midpoint"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=midpoint]]></Tracking><Tracking event="thirdQuartile"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=thirdQuartile]]></Tracking><Tracking event="complete"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=complete]]></Tracking><Tracking event="mute"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=mute]]></Tracking><Tracking event="unmute"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=unmute]]></Tracking><Tracking event="pause"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=pause]]></Tracking><Tracking event="resume"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=resume]]></Tracking><Tracking event="fullscreen"><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=fullscreen]]></Tracking></TrackingEvents><VideoClicks><ClickTracking><![CDATA[http://manage.newmanage.aniview.com/track?d=&cou=IL&cos=Android&r=play.aniview.com&rs=play.aniview.com&sid=71720&t=1549448635&cip=46.116.196.171&sn=&tgt=0&osv=6&bv=&brn=Chrome&wi=640&he=480&app=&AV_PUBLISHERID=55b78633181f4603178b4568&test=&aafaid=&cb=4293171175&asid=55b78d94181f46290f8b456a&pid=55b78633181f4603178b4568&cid=55b7904d181f46410f8b4568&h=b304444f9f8c28b12421555fef487f08e954c587&e=click]]></ClickTracking><ClickThrough id="VideoHub"><![CDATA[http://www.ford.com/]]></ClickThrough></VideoClicks><MediaFiles><MediaFile height="360" width="480" bitrate="527" type="video/mp4" delivery="progressive"><![CDATA[https://play.aniview.com/clients/ford2.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives><Extensions><Extension type="ANIVIEW"><AdServingSync><![CDATA[{"trackers":[' + pixelStr + ']}]]></AdServingSync><AdServingData><Asid><![CDATA[55b78d94181f46290f8b456a]]></Asid><Nasid><![CDATA[55b78d94181f46290f8b456a]]></Nasid><Cpm><![CDATA[2]]></Cpm><PlayerSettings><![CDATA[{"vpp":1,"fp":0,"maxRPM":0,"vit":3,"nc":"1","mips":0,"mrqs":0,"vpm":0,"vi":0,"t": 1,"res": 5}]]></PlayerSettings></AdServingData></Extension></Extensions></InLine></Ad></VAST>';
let serverResponse = [
{body: bidResponse}
];
let syncPixels = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, serverResponse);
expect(syncPixels.length).to.equal(1);
let pixel = syncPixels[0];
expect(pixel.url).to.equal(pixelUrl);
expect(pixel.type).to.equal('iframe');
});
});
});

0 comments on commit 991ad56

Please sign in to comment.