Skip to content

Commit

Permalink
Magnite Analytics Adapter: add indication of cookieless traffic (preb…
Browse files Browse the repository at this point in the history
  • Loading branch information
apukh-magnite authored Mar 20, 2024
1 parent b1d4679 commit 31f7581
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
16 changes: 15 additions & 1 deletion modules/magniteAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const pbsErrorMap = {
4: 'request-error',
999: 'generic-error'
}
let cookieless;

let prebidGlobal = getGlobal();
const {
Expand Down Expand Up @@ -332,10 +333,14 @@ const getTopLevelDetails = () => {

// Add DM wrapper details
if (rubiConf.wrapperName) {
let rule;
if (cookieless) {
rule = rubiConf.rule_name ? rubiConf.rule_name.concat('_cookieless') : 'cookieless';
}
payload.wrapper = {
name: rubiConf.wrapperName,
family: rubiConf.wrapperFamily,
rule: rubiConf.rule_name
rule
}
}

Expand Down Expand Up @@ -823,6 +828,15 @@ magniteAdapter.track = ({ eventType, args }) => {
auctionData.floors = addFloorData(floorData);
}

// Identify chrome cookieless trafic
if (!cookieless) {
const cdep = deepAccess(args, 'bidderRequests.0.ortb2.device.ext.cdep');
if (cdep && (cdep.indexOf('treatment') !== -1 || cdep.indexOf('control_2') !== -1)) {
cookieless = 1;
auctionData.cdep = 1;
}
}

// GDPR info
const gdprData = deepAccess(args, 'bidderRequests.0.gdprConsent');
if (gdprData) {
Expand Down
73 changes: 73 additions & 0 deletions test/spec/modules/magniteAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,79 @@ describe('magnite analytics adapter', function () {
expect(message1.bidsWon).to.deep.equal([expectedMessage1]);
});
});
describe('cookieless', () => {
beforeEach(() => {
magniteAdapter.enableAnalytics({
options: {
cookieles: undefined
}
});
})
afterEach(() => {
magniteAdapter.disableAnalytics();
})
it('should add sufix _cookieless to the wrapper.rule if ortb2.device.ext.cdep start with "treatment" or "control_2"', () => {
// Set the confs
config.setConfig({
rubicon: {
wrapperName: '1001_general',
wrapperFamily: 'general',
rule_name: 'desktop-magnite.com',
}
});
const auctionId = MOCK.AUCTION_INIT.auctionId;

let auctionInit = utils.deepClone(MOCK.AUCTION_INIT);
auctionInit.bidderRequests[0].ortb2.device.ext = { cdep: 'treatment' };
// Run auction
events.emit(AUCTION_INIT, auctionInit);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
[gptSlotRenderEnded0].forEach(gptEvent => mockGpt.emitEvent(gptEvent.eventName, gptEvent.params));
events.emit(BID_WON, { ...MOCK.BID_WON, auctionId });
clock.tick(rubiConf.analyticsEventDelay);
expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);
expect(message.wrapper).to.deep.equal({
name: '1001_general',
family: 'general',
rule: 'desktop-magnite.com_cookieless',
});
})
it('should add cookieless to the wrapper.rule if ortb2.device.ext.cdep start with "treatment" or "control_2"', () => {
// Set the confs
config.setConfig({
rubicon: {
wrapperName: '1001_general',
wrapperFamily: 'general',
}
});
const auctionId = MOCK.AUCTION_INIT.auctionId;

let auctionInit = utils.deepClone(MOCK.AUCTION_INIT);
auctionInit.bidderRequests[0].ortb2.device.ext = { cdep: 'control_2' };
// Run auction
events.emit(AUCTION_INIT, auctionInit);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
[gptSlotRenderEnded0].forEach(gptEvent => mockGpt.emitEvent(gptEvent.eventName, gptEvent.params));
events.emit(BID_WON, { ...MOCK.BID_WON, auctionId });
clock.tick(rubiConf.analyticsEventDelay);
expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);
expect(message.wrapper).to.deep.equal({
family: 'general',
name: '1001_general',
rule: 'cookieless',
});
});
});
});

describe('billing events integration', () => {
Expand Down

0 comments on commit 31f7581

Please sign in to comment.