Skip to content

Commit fe23164

Browse files
Concert Bid Adapter: Update localStorage name-spacing for Concert UID (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 <[email protected]> Co-authored-by: Antoin <[email protected]>
1 parent 6d114e8 commit fe23164

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

modules/concertBidAdapter.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { logWarn, logMessage, debugTurnedOn, generateUUID } from '../src/utils.js';
1+
import { logWarn, logMessage, debugTurnedOn, generateUUID, deepAccess } from '../src/utils.js';
22
import { registerBidder } from '../src/adapters/bidderFactory.js';
33
import { getStorageManager } from '../src/storageManager.js';
44
import { hasPurpose1Consent } from '../src/utils/gpdr.js';
@@ -178,7 +178,7 @@ export const spec = {
178178

179179
registerBidder(spec);
180180

181-
const storage = getStorageManager({bidderCode: BIDDER_CODE});
181+
export const storage = getStorageManager({bidderCode: BIDDER_CODE});
182182

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

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

193+
if (sharedId) {
194+
return sharedId;
195+
}
196+
197+
const LEGACY_CONCERT_UID_KEY = 'c_uid';
198+
const CONCERT_UID_KEY = 'vmconcert_uid';
199+
200+
const legacyUid = storage.getDataFromLocalStorage(LEGACY_CONCERT_UID_KEY);
193201
let uid = storage.getDataFromLocalStorage(CONCERT_UID_KEY);
194202

203+
if (legacyUid) {
204+
uid = legacyUid;
205+
storage.setDataInLocalStorage(CONCERT_UID_KEY, uid);
206+
storage.removeDataFromLocalStorage(LEGACY_CONCERT_UID_KEY);
207+
}
208+
195209
if (!uid) {
196210
uid = generateUUID();
197211
storage.setDataInLocalStorage(CONCERT_UID_KEY, uid);

test/spec/modules/concertBidAdapter_spec.js

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import sinon from 'sinon';
3-
import { spec } from 'modules/concertBidAdapter.js';
4-
import { getStorageManager } from '../../../src/storageManager.js'
3+
import { spec, storage } from 'modules/concertBidAdapter.js';
4+
import { hook } from 'src/hook.js';
55

66
describe('ConcertAdapter', function () {
77
let bidRequests;
@@ -10,9 +10,8 @@ describe('ConcertAdapter', function () {
1010
let element;
1111
let sandbox;
1212

13-
afterEach(function () {
14-
$$PREBID_GLOBAL$$.bidderSettings = {};
15-
sandbox.restore();
13+
before(function () {
14+
hook.ready();
1615
});
1716

1817
beforeEach(function () {
@@ -39,6 +38,7 @@ describe('ConcertAdapter', function () {
3938
storageAllowed: true
4039
}
4140
};
41+
4242
bidRequests = [
4343
{
4444
bidder: 'concert',
@@ -83,6 +83,11 @@ describe('ConcertAdapter', function () {
8383
sandbox.stub(document, 'getElementById').withArgs('desktop_leaderboard_variable').returns(element)
8484
});
8585

86+
afterEach(function () {
87+
$$PREBID_GLOBAL$$.bidderSettings = {};
88+
sandbox.restore();
89+
});
90+
8691
describe('spec.isBidRequestValid', function() {
8792
it('should return when it recieved all the required params', function() {
8893
const bid = bidRequests[0];
@@ -118,7 +123,6 @@ describe('ConcertAdapter', function () {
118123
});
119124

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

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

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

138-
it('should grab uid from local storage if it exists', function() {
139-
const storage = getStorageManager();
140-
storage.setDataInLocalStorage('c_uid', 'foo');
141+
it('should use sharedid if it exists', function() {
142+
storage.removeDataFromLocalStorage('c_nap');
143+
const request = spec.buildRequests(bidRequests, {
144+
...bidRequest,
145+
userId: {
146+
_sharedid: {
147+
id: '123abc'
148+
}
149+
}
150+
});
151+
const payload = JSON.parse(request.data);
152+
expect(payload.meta.uid).to.equal('123abc');
153+
})
154+
155+
it('should grab uid from local storage if it exists and sharedid does not', function() {
156+
storage.setDataInLocalStorage('vmconcert_uid', 'foo');
141157
storage.removeDataFromLocalStorage('c_nap');
142158
const request = spec.buildRequests(bidRequests, bidRequest);
143159
const payload = JSON.parse(request.data);
@@ -211,7 +227,6 @@ describe('ConcertAdapter', function () {
211227
const opts = {
212228
iframeEnabled: true
213229
};
214-
const storage = getStorageManager();
215230
storage.setDataInLocalStorage('c_nap', 'true');
216231

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

228242
bidRequest.gdprConsent = {
@@ -237,7 +251,6 @@ describe('ConcertAdapter', function () {
237251
const opts = {
238252
iframeEnabled: true
239253
};
240-
const storage = getStorageManager();
241254
storage.removeDataFromLocalStorage('c_nap');
242255

243256
bidRequest.gdprConsent = {
@@ -252,7 +265,6 @@ describe('ConcertAdapter', function () {
252265
const opts = {
253266
iframeEnabled: true
254267
};
255-
const storage = getStorageManager();
256268
storage.removeDataFromLocalStorage('c_nap');
257269

258270
bidRequest.gdprConsent = {
@@ -268,7 +280,6 @@ describe('ConcertAdapter', function () {
268280
const opts = {
269281
iframeEnabled: true
270282
};
271-
const storage = getStorageManager();
272283
storage.removeDataFromLocalStorage('c_nap');
273284

274285
bidRequest.gdprConsent = {

0 commit comments

Comments
 (0)