-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpex Id System: initial release (#8364)
* Adds cpexIdSystem * Fixes cpexIdSystem tests * Added markdown document * Remove unnecessary storage config
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); | ||
}); | ||
}); | ||
}); |