Skip to content

Commit

Permalink
cpex Id System: initial release (#8364)
Browse files Browse the repository at this point in the history
* Adds cpexIdSystem

* Fixes cpexIdSystem tests

* Added markdown document

* Remove unnecessary storage config
  • Loading branch information
EskelCz authored May 10, 2022
1 parent 87b7dc8 commit 8a4fd44
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"amxIdSystem",
"britepoolIdSystem",
"connectIdSystem",
"cpexIdSystem",
"criteoIdSystem",
"dacIdSystem",
"deepintentDpesIdSystem",
Expand Down
49 changes: 49 additions & 0 deletions modules/cpexIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* This module adds 'caid' to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/cpexIdSystem
* @requires module:modules/userId
*/

import { submodule } from '../src/hook.js'
import { getStorageManager } from '../src/storageManager.js'

window.top.cpexIdVersion = '0.0.3'

// Returns StorageManager
export const storage = getStorageManager({ gvlid: 570, moduleName: 'cpexId' })

// Returns the id string from either cookie or localstorage
const getId = () => { return storage.getCookie('caid') || storage.getDataFromLocalStorage('caid') }

/** @type {Submodule} */
export const cpexIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'cpexId',
/**
* Vendor ID of Czech Publisher Exchange
* @type {Number}
*/
gvlid: 570,
/**
* decode the stored id value for passing to bid requests
* @function decode
* @param {(Object|string)} value
* @returns {(Object|undefined)}
*/
decode (value) { return { cpexId: getId() } },
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleConfig} [config]
* @param {ConsentData} [consentData]
* @param {(Object|undefined)} cacheIdObj
* @returns {IdResponse|undefined}
*/
getId (config, consentData) { return { cpexId: getId() } }
}

submodule('userId', cpexIdSubmodule)
27 changes: 27 additions & 0 deletions modules/cpexIdSystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## CPEx User ID Submodule

CPExID is provided by [Czech Publisher Exchange](https://www.cpex.cz/), or CPEx. It is a user ID for ad targeting by using first party cookie, or localStorage mechanism. Please contact CPEx before using this ID.

## Building Prebid with CPExID Support

First, make sure to add the cpexId to your Prebid.js package with:

```
gulp build --modules=cpexIdSystem
```

The following configuration parameters are available:

```javascript
pbjs.setConfig({
userSync: {
userIds: [{
name: 'cpexId'
}]
}
});
```

| Param under userSync.userIds[] | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | The name of this module. | `"cpexId"` |
2 changes: 2 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pbjs.setConfig({
name: '_criteoId',
expires: 1
}
}, {
name: "cpexId"
}, {
name: 'mwOpenLinkId',
params: {
Expand Down
38 changes: 38 additions & 0 deletions test/spec/modules/cpexIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { cpexIdSubmodule, storage } from 'modules/cpexIdSystem.js';

describe('cpexId module', function () {
let getCookieStub;

beforeEach(function (done) {
getCookieStub = sinon.stub(storage, 'getCookie');
done();
});

afterEach(function () {
getCookieStub.restore();
});

const cookieTestCasesForEmpty = [undefined, null, '']

describe('getId()', function () {
it('should return the uid when it exists in cookie', function () {
getCookieStub.withArgs('caid').returns('cpexIdTest');
const id = cpexIdSubmodule.getId();
expect(id).to.be.deep.equal({ cpexId: 'cpexIdTest' });
});

cookieTestCasesForEmpty.forEach(testCase => it('should not return the uid when it doesnt exist in cookie', function () {
getCookieStub.withArgs('caid').returns(testCase);
const id = cpexIdSubmodule.getId();
expect(id).to.be.deep.equal({ cpexId: null });
}));
});

describe('decode()', function () {
it('should return the uid when it exists in cookie', function () {
getCookieStub.withArgs('caid').returns('cpexIdTest');
const decoded = cpexIdSubmodule.decode();
expect(decoded).to.be.deep.equal({ cpexId: 'cpexIdTest' });
});
});
});

0 comments on commit 8a4fd44

Please sign in to comment.