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

Nexx360 Bid Adapter: Additional localStorage information #11466

Merged
merged 8 commits into from
May 29, 2024
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
36 changes: 33 additions & 3 deletions modules/nexx360BidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const OUTSTREAM_RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstre
const BIDDER_CODE = 'nexx360';
const REQUEST_URL = 'https://fast.nexx360.io/booster';
const PAGE_VIEW_ID = generateUUID();
const BIDDER_VERSION = '4.0';
const BIDDER_VERSION = '4.1';
const GVLID = 965;
const NEXXID_KEY = 'nexx360_storage';

Expand Down Expand Up @@ -69,6 +69,19 @@ function getAdContainer(container) {
}
}

/**
* Get the AMX ID
* @return {string | false } false if localstorageNotEnabled
*/
export function getAmxId() {
if (!storage.localStorageIsEnabled()) {
logInfo(`localstorage not enabled for Nexx360`);
return false;
}
const amxId = storage.getDataFromLocalStorage('__amuidpb');
return amxId || false;
}

const converter = ortbConverter({
context: {
netRevenue: true, // or false if your adapter should set bidResponse.netRevenue = false
Expand Down Expand Up @@ -107,13 +120,30 @@ const converter = ortbConverter({
request(buildRequest, imps, bidderRequest, context) {
const request = buildRequest(imps, bidderRequest, context);
const nexx360LocalStorage = getNexx360LocalStorage();
if (nexx360LocalStorage) deepSetValue(request, 'ext.nexx360Id', nexx360LocalStorage.nexx360Id);
if (nexx360LocalStorage) {
deepSetValue(request, 'ext.nexx360Id', nexx360LocalStorage.nexx360Id);
deepSetValue(request, 'ext.localStorage.nexx360Id', nexx360LocalStorage.nexx360Id);
}
const amxId = getAmxId();
if (amxId) deepSetValue(request, 'ext.localStorage.amxId', amxId());
deepSetValue(request, 'ext.version', '$prebid.version$');
deepSetValue(request, 'ext.source', 'prebid.js');
deepSetValue(request, 'ext.pageViewId', PAGE_VIEW_ID);
deepSetValue(request, 'ext.bidderVersion', BIDDER_VERSION);
deepSetValue(request, 'cur', [config.getConfig('currency.adServerCurrency') || 'USD']);
if (!request.user) deepSetValue(request, 'user', {});
if (!request.user) request.user = {};
if (getAmxId()) {
if (!request.user.ext) request.user.ext = {};
if (!request.user.ext.eids) request.user.ext.eids = [];
request.user.ext.eids.push({
source: 'amxdt.net',
uids: [{
id: `${getAmxId()}`,
atype: 1
}]
});
}

return request;
},
});
Expand Down
37 changes: 34 additions & 3 deletions test/spec/modules/nexx360BidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
spec, storage, getNexx360LocalStorage,
} from 'modules/nexx360BidAdapter.js';
import { sandbox } from 'sinon';
import { getAmxId } from '../../../modules/nexx360BidAdapter';

const instreamResponse = {
'id': '2be64380-ba0c-405a-ab53-51f51c7bde51',
Expand Down Expand Up @@ -220,7 +221,7 @@ describe('Nexx360 bid adapter tests', function () {
after(function () {
sandbox.restore()
});
})
});

describe('getNexx360LocalStorage enabled', function () {
before(function () {
Expand All @@ -235,7 +236,37 @@ describe('Nexx360 bid adapter tests', function () {
after(function () {
sandbox.restore()
});
})
});

describe('getAmxId() with localStorage enabled and data not set', function() {
before(function () {
sandbox.stub(storage, 'localStorageIsEnabled').callsFake(() => true);
sandbox.stub(storage, 'setDataInLocalStorage');
sandbox.stub(storage, 'getDataFromLocalStorage').callsFake((key) => null);
});
it('We test if we get the amxId', function() {
const output = getAmxId();
expect(output).to.be.eql(false);
});
after(function () {
sandbox.restore()
});
});

describe('getAmxId() with localStorage enabled and data set', function() {
before(function () {
sandbox.stub(storage, 'localStorageIsEnabled').callsFake(() => true);
sandbox.stub(storage, 'setDataInLocalStorage');
sandbox.stub(storage, 'getDataFromLocalStorage').callsFake((key) => 'abcdef');
});
it('We test if we get the amxId', function() {
const output = getAmxId();
expect(output).to.be.eql('abcdef');
});
after(function () {
sandbox.restore()
});
});

describe('buildRequests()', function() {
before(function () {
Expand Down Expand Up @@ -374,7 +405,7 @@ describe('Nexx360 bid adapter tests', function () {
expect(requestContent.imp[1].tagid).to.be.eql('div-2-abcd');
expect(requestContent.imp[1].ext.adUnitCode).to.be.eql('div-2-abcd');
expect(requestContent.imp[1].ext.divId).to.be.eql('div-2-abcd');
expect(requestContent.ext.bidderVersion).to.be.eql('4.0');
expect(requestContent.ext.bidderVersion).to.be.eql('4.1');
expect(requestContent.ext.source).to.be.eql('prebid.js');
});

Expand Down