Skip to content

Commit

Permalink
Cee id System: add custom token name and optional value to pass (#11547)
Browse files Browse the repository at this point in the history
* Update tests for sspBC adapter

Update tests for sspBC adapter:
- change userSync test (due to tcf param appended in v4.6)
- add tests for onBidWon and onTimeout

* [sspbc-adapter] 5.3 updates: content-type for notifications

* [sspbc-adapter] pass CTA to native bid

* [sspbc-5.3] keep pbsize for detected adunits

* [maintenance] - remove old test for sspBc bid adaptor

* [sspbc-5.3] increment adaptor ver

* [sspbc-adapter] maintenance update to sspBCBidAdapter

* remove yarn.lock

* Delete package-lock.json

* remove package-lock.jsonfrom pull request

* [sspbc-adapter] send pageViewId in request

* [sspbc-adapter] update pageViewId test

* [sspbc-adapter] add viewabiility tracker to native ads

* [sspbc-adapter] add support for bid.admNative property

* [sspbc-adapter] ensure that placement id length is always 3 (improves matching response to request)

* [sspbc-adapter] read publisher id and custom ad label, then send them to banner creative

* [sspbc-adapter] adlabel and pubid are set as empty strings, if not present in bid response

* [sspbc-adapter] jstracker data fix

* [sspbc-adapter] jstracker data fix

* [sspbc-adapter] send tagid in notifications

* [sspbc-adapter] add gvlid to spec; prepare getUserSyncs for iframe + image sync

* update remote repo

* cleanup of grupawp/prebid master branch

* update sspBC adapter to v 5.9

* update tests for sspBC bid adapter

* [sspbc-adapter] add support for topicsFPD module

* [sspbc-adapter] change topic segment ids to int

* add pirIdSystem

* pirIdSystem

* piridSystem - preCR

* fix after CR

* name change

* custom token name read + optional token value

---------

Co-authored-by: wojciech-bialy-wpm <67895844+wojciech-bialy-wpm@users.noreply.github.com>
Co-authored-by: Wojciech Biały <wb@WojciechBialy.local>
Co-authored-by: Wojciech Biały <wojciech.bialy@grupawp.pl>
  • Loading branch information
4 people authored Jun 7, 2024
1 parent e3ea280 commit 203ebe5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 11 deletions.
11 changes: 6 additions & 5 deletions modules/ceeIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import {domainOverrideToRootDomain} from '../libraries/domainOverrideToRootDomai
*/

const MODULE_NAME = 'ceeId';
const ID_TOKEN = 'WPxid';
export const storage = getStorageManager({ moduleName: MODULE_NAME, moduleType: MODULE_TYPE_UID });

/**
* Reads the ID token from local storage or cookies.
* @returns {string|undefined} The ID token, or undefined if not found.
*/
export const readId = () => storage.getDataFromLocalStorage(ID_TOKEN) || storage.getCookie(ID_TOKEN);
export const readId = tokenName => storage.getDataFromLocalStorage(tokenName) || storage.getCookie(tokenName);

/** @type {Submodule} */
export const ceeIdSubmodule = {
Expand All @@ -44,9 +43,11 @@ export const ceeIdSubmodule = {
* performs action to obtain id and return a value
* @function
* @returns {(IdResponse|undefined)}
*/
getId() {
const ceeIdToken = readId();
*/
getId(config) {
const { params = {} } = config;
const { tokenName, value } = params
const ceeIdToken = value || readId(tokenName);

return ceeIdToken ? { id: ceeIdToken } : undefined;
},
Expand Down
4 changes: 4 additions & 0 deletions modules/ceeIdSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pbjs.setConfig({
name: 'ceeIdToken',
expires: 7,
refreshInSeconds: 360
},
params: {
tokenName: 'name' // Your custom name of token to read
value: 'tokenValue' // Optional param if you want to pass token value directly through setConfig (this param shouldn't be set if token value will be taken from cookie or LS)
}
}]
}
Expand Down
66 changes: 60 additions & 6 deletions test/spec/modules/ceeIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,65 @@ describe('ceeIdSystem', () => {
});

describe('getId', () => {
it('should return an object with id when ceeIdToken is found', () => {
it('should return an object with id when ceeIdToken is found in LS', () => {
const config = {
name: 'ceeId',
storage: {
type: 'cookie',
name: 'ceeIdToken',
expires: 7,
refreshInSeconds: 360,
},
params: {
tokenName: 'WPxid',
},
};

getDataFromLocalStorageStub.returns('testToken');
getCookieStub.returns('testToken');

const result = ceeIdSubmodule.getId();
const result = ceeIdSubmodule.getId(config);

expect(result).to.deep.equal({ id: 'testToken' });
});

it('should return an object with id when ceeIdToken is passed in setConfig', () => {
const config = {
name: 'ceeId',
storage: {
type: 'cookie',
name: 'ceeIdToken',
expires: 7,
refreshInSeconds: 360,
},
params: {
tokenName: 'WPxid',
value: 'testTokenFromSetConfig'
},
};

getDataFromLocalStorageStub.returns('testToken');
getCookieStub.returns('testToken');

const result = ceeIdSubmodule.getId(config);

expect(result).to.deep.equal({ id: 'testTokenFromSetConfig' });
});

it('should return undefined when ceeIdToken is not found', () => {
const result = ceeIdSubmodule.getId();
const config = {
name: 'ceeId',
storage: {
type: 'cookie',
name: 'ceeIdToken',
expires: 7,
refreshInSeconds: 360,
},
params: {
tokenName: 'WPxid',
},
};
const result = ceeIdSubmodule.getId(config);

expect(result).to.be.undefined;
});
Expand All @@ -49,27 +97,33 @@ describe('ceeIdSystem', () => {

describe('readId', () => {
it('should return data from local storage when it exists', () => {
const tokenName = 'testToken';

getDataFromLocalStorageStub.returns('local_storage_data');

const result = readId();
const result = readId(tokenName);

expect(result).to.equal('local_storage_data');
});

it('should return data from cookie when local storage data does not exist', () => {
const tokenName = 'testToken';

getDataFromLocalStorageStub.returns(null);
getCookieStub.returns('cookie_data');

const result = readId();
const result = readId(tokenName);

expect(result).to.equal('cookie_data');
});

it('should return null when neither local storage data nor cookie data exists', () => {
const tokenName = 'testToken';

getDataFromLocalStorageStub.returns(null);
getCookieStub.returns(null);

const result = readId();
const result = readId(tokenName);

expect(result).to.be.null;
});
Expand Down

0 comments on commit 203ebe5

Please sign in to comment.