Skip to content

Commit

Permalink
Concert Bid Adapter: Update localStorage name-spacing for Concert UID (
Browse files Browse the repository at this point in the history
…prebid#9158)

* collect EIDs for bid request

* add ad slot positioning to payload

* RPO-2012: Update local storage name-spacing for c_uid (#8)

* Updates c_uid namespacing to be more specific for concert

* fixes unit tests

* remove console.log

* RPO-2012: Add check for shared id (#9)

* Adds check for sharedId

* Updates cookie name

* remove trailing comma

Co-authored-by: antoin <antoin.campbell@voxmedia.com>
Co-authored-by: Antoin <antoinfive@gmail.com>
  • Loading branch information
3 people authored Nov 8, 2022
1 parent 6d114e8 commit fe23164
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
20 changes: 17 additions & 3 deletions modules/concertBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logWarn, logMessage, debugTurnedOn, generateUUID } from '../src/utils.js';
import { logWarn, logMessage, debugTurnedOn, generateUUID, deepAccess } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import { hasPurpose1Consent } from '../src/utils/gpdr.js';
Expand Down Expand Up @@ -178,7 +178,7 @@ export const spec = {

registerBidder(spec);

const storage = getStorageManager({bidderCode: BIDDER_CODE});
export const storage = getStorageManager({bidderCode: BIDDER_CODE});

/**
* Check or generate a UID for the current user.
Expand All @@ -188,10 +188,24 @@ function getUid(bidderRequest) {
return false;
}

const CONCERT_UID_KEY = 'c_uid';
const sharedId = deepAccess(bidderRequest, 'userId._sharedid.id');

if (sharedId) {
return sharedId;
}

const LEGACY_CONCERT_UID_KEY = 'c_uid';
const CONCERT_UID_KEY = 'vmconcert_uid';

const legacyUid = storage.getDataFromLocalStorage(LEGACY_CONCERT_UID_KEY);
let uid = storage.getDataFromLocalStorage(CONCERT_UID_KEY);

if (legacyUid) {
uid = legacyUid;
storage.setDataInLocalStorage(CONCERT_UID_KEY, uid);
storage.removeDataFromLocalStorage(LEGACY_CONCERT_UID_KEY);
}

if (!uid) {
uid = generateUUID();
storage.setDataInLocalStorage(CONCERT_UID_KEY, uid);
Expand Down
41 changes: 26 additions & 15 deletions test/spec/modules/concertBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { spec } from 'modules/concertBidAdapter.js';
import { getStorageManager } from '../../../src/storageManager.js'
import { spec, storage } from 'modules/concertBidAdapter.js';
import { hook } from 'src/hook.js';

describe('ConcertAdapter', function () {
let bidRequests;
Expand All @@ -10,9 +10,8 @@ describe('ConcertAdapter', function () {
let element;
let sandbox;

afterEach(function () {
$$PREBID_GLOBAL$$.bidderSettings = {};
sandbox.restore();
before(function () {
hook.ready();
});

beforeEach(function () {
Expand All @@ -39,6 +38,7 @@ describe('ConcertAdapter', function () {
storageAllowed: true
}
};

bidRequests = [
{
bidder: 'concert',
Expand Down Expand Up @@ -83,6 +83,11 @@ describe('ConcertAdapter', function () {
sandbox.stub(document, 'getElementById').withArgs('desktop_leaderboard_variable').returns(element)
});

afterEach(function () {
$$PREBID_GLOBAL$$.bidderSettings = {};
sandbox.restore();
});

describe('spec.isBidRequestValid', function() {
it('should return when it recieved all the required params', function() {
const bid = bidRequests[0];
Expand Down Expand Up @@ -118,7 +123,6 @@ describe('ConcertAdapter', function () {
});

it('should not generate uid if the user has opted out', function() {
const storage = getStorageManager();
storage.setDataInLocalStorage('c_nap', 'true');
const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);
Expand All @@ -127,17 +131,29 @@ describe('ConcertAdapter', function () {
});

it('should generate uid if the user has not opted out', function() {
const storage = getStorageManager();
storage.removeDataFromLocalStorage('c_nap');
const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);

expect(payload.meta.uid).to.not.equal(false);
});

it('should grab uid from local storage if it exists', function() {
const storage = getStorageManager();
storage.setDataInLocalStorage('c_uid', 'foo');
it('should use sharedid if it exists', function() {
storage.removeDataFromLocalStorage('c_nap');
const request = spec.buildRequests(bidRequests, {
...bidRequest,
userId: {
_sharedid: {
id: '123abc'
}
}
});
const payload = JSON.parse(request.data);
expect(payload.meta.uid).to.equal('123abc');
})

it('should grab uid from local storage if it exists and sharedid does not', function() {
storage.setDataInLocalStorage('vmconcert_uid', 'foo');
storage.removeDataFromLocalStorage('c_nap');
const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);
Expand Down Expand Up @@ -211,7 +227,6 @@ describe('ConcertAdapter', function () {
const opts = {
iframeEnabled: true
};
const storage = getStorageManager();
storage.setDataInLocalStorage('c_nap', 'true');

const sync = spec.getUserSyncs(opts, [], bidRequest.gdprConsent, bidRequest.uspConsent);
Expand All @@ -222,7 +237,6 @@ describe('ConcertAdapter', function () {
const opts = {
iframeEnabled: true
};
const storage = getStorageManager();
storage.removeDataFromLocalStorage('c_nap');

bidRequest.gdprConsent = {
Expand All @@ -237,7 +251,6 @@ describe('ConcertAdapter', function () {
const opts = {
iframeEnabled: true
};
const storage = getStorageManager();
storage.removeDataFromLocalStorage('c_nap');

bidRequest.gdprConsent = {
Expand All @@ -252,7 +265,6 @@ describe('ConcertAdapter', function () {
const opts = {
iframeEnabled: true
};
const storage = getStorageManager();
storage.removeDataFromLocalStorage('c_nap');

bidRequest.gdprConsent = {
Expand All @@ -268,7 +280,6 @@ describe('ConcertAdapter', function () {
const opts = {
iframeEnabled: true
};
const storage = getStorageManager();
storage.removeDataFromLocalStorage('c_nap');

bidRequest.gdprConsent = {
Expand Down

0 comments on commit fe23164

Please sign in to comment.