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

Concert Bid Adapter: Update localStorage name-spacing for Concert UID #9158

Merged
merged 9 commits into from
Nov 8, 2022
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, ty

}

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