-
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.
Dacid User Id Module: add new id module (#8187)
* Add dacid user id module * Fix source domain * Add document to explain dac ID
- Loading branch information
1 parent
89a6271
commit 822a045
Showing
7 changed files
with
149 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
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,57 @@ | ||
/** | ||
* This module adds dacId to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/dacIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import { submodule } from '../src/hook.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
|
||
export const storage = getStorageManager(); | ||
|
||
export const cookieKey = '_a1_f'; | ||
|
||
export const dacIdSystemSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: 'dacId', | ||
|
||
/** | ||
* performs action to obtain id | ||
* @function | ||
* @returns { {id: {dacId: string}} | undefined } | ||
*/ | ||
getId: function() { | ||
const newId = storage.getCookie(cookieKey); | ||
if (!newId) { | ||
return undefined; | ||
} | ||
const result = { | ||
dacId: newId | ||
} | ||
return {id: result}; | ||
}, | ||
|
||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @param { {dacId: string} } value | ||
* @returns { {dacId: {id: string} } | undefined } | ||
*/ | ||
decode: function(value) { | ||
if (value && typeof value === 'object') { | ||
const result = {}; | ||
if (value.dacId) { | ||
result.id = value.dacId | ||
} | ||
return {dacId: result}; | ||
} | ||
return undefined; | ||
}, | ||
|
||
} | ||
|
||
submodule('userId', dacIdSystemSubmodule); |
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,28 @@ | ||
## DAC User ID Submodule | ||
|
||
DAC ID, provided by [D.A.Consortium Inc.](https://www.dac.co.jp/), is ID for ad targeting by using 1st party cookie. | ||
Please contact D.A.Consortium Inc. before using this ID. | ||
|
||
## Building Prebid with DAC ID Support | ||
|
||
First, make sure to add the DAC ID submodule to your Prebid.js package with: | ||
|
||
``` | ||
gulp build --modules=dacIdSystem | ||
``` | ||
|
||
The following configuration parameters are available: | ||
|
||
```javascript | ||
pbjs.setConfig({ | ||
userSync: { | ||
userIds: [{ | ||
name: 'dacId' | ||
}] | ||
} | ||
}); | ||
``` | ||
|
||
| Param under userSync.userIds[] | Scope | Type | Description | Example | | ||
| --- | --- | --- | --- | --- | | ||
| name | Required | String | The name of this module. | `"dacId"` | |
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
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,51 @@ | ||
import { dacIdSystemSubmodule, storage, cookieKey } from 'modules/dacIdSystem.js'; | ||
|
||
const DACID_DUMMY_VALUE = 'dacIdTest'; | ||
const DACID_DUMMY_OBJ = { | ||
dacId: DACID_DUMMY_VALUE | ||
}; | ||
|
||
describe('dacId 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(cookieKey).returns(DACID_DUMMY_VALUE); | ||
const id = dacIdSystemSubmodule.getId(); | ||
expect(id).to.be.deep.equal({id: {dacId: DACID_DUMMY_VALUE}}); | ||
}); | ||
|
||
cookieTestCasesForEmpty.forEach(testCase => it('should return the uid when it not exists in cookie', function () { | ||
getCookieStub.withArgs(cookieKey).returns(testCase); | ||
const id = dacIdSystemSubmodule.getId(); | ||
expect(id).to.be.deep.equal(undefined); | ||
})); | ||
}); | ||
|
||
describe('decode()', function () { | ||
it('should return the uid when it exists in cookie', function () { | ||
const decoded = dacIdSystemSubmodule.decode(DACID_DUMMY_OBJ); | ||
expect(decoded).to.be.deep.equal({dacId: {id: DACID_DUMMY_VALUE}}); | ||
}); | ||
|
||
it('should return the undefined when decode id is not "string"', function () { | ||
const decoded = dacIdSystemSubmodule.decode(1); | ||
expect(decoded).to.equal(undefined); | ||
}); | ||
}); | ||
}); |