forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gravito User Id submodule: initial release (prebid#8414)
* gravitompId user module for integrating gravito first party cookie with prebid js * fixed eslint issues raised by circleci * fixed trailing spaces error raised by circleci
- Loading branch information
1 parent
26380c1
commit 89535f5
Showing
7 changed files
with
150 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,9 @@ | |
}, | ||
{ | ||
"name": "dacId" | ||
}, | ||
{ | ||
"name": "gravitompId" | ||
} | ||
], | ||
"syncDelay": 5000, | ||
|
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 gravitompId to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/gravitoIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import { submodule } from '../src/hook.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
|
||
export const storage = getStorageManager(); | ||
|
||
export const cookieKey = 'gravitompId'; | ||
|
||
export const gravitoIdSystemSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: 'gravitompId', | ||
|
||
/** | ||
* performs action to obtain id | ||
* @function | ||
* @returns { {id: {gravitompId: string}} | undefined } | ||
*/ | ||
getId: function() { | ||
const newId = storage.getCookie(cookieKey); | ||
if (!newId) { | ||
return undefined; | ||
} | ||
const result = { | ||
gravitompId: newId | ||
} | ||
return {id: result}; | ||
}, | ||
|
||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @param { {gravitompId: string} } value | ||
* @returns { {gravitompId: {id: string} } | undefined } | ||
*/ | ||
decode: function(value) { | ||
if (value && typeof value === 'object') { | ||
const result = {}; | ||
if (value.gravitompId) { | ||
result.id = value.gravitompId | ||
} | ||
return {gravitompId: result}; | ||
} | ||
return undefined; | ||
}, | ||
|
||
} | ||
|
||
submodule('userId', gravitoIdSystemSubmodule); |
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 @@ | ||
## Gravito User ID Submodule | ||
|
||
Gravito ID, provided by [Gravito Ltd.](https://gravito.net), is ID for ad targeting by using 1st party cookie. | ||
Please contact Gravito Ltd. before using this ID. | ||
|
||
## Building Prebid with Gravito ID Support | ||
|
||
First, make sure to add the Gravito ID submodule to your Prebid.js package with: | ||
|
||
``` | ||
gulp build --modules=gravitoIdSystem | ||
``` | ||
|
||
The following configuration parameters are available: | ||
|
||
```javascript | ||
pbjs.setConfig({ | ||
userSync: { | ||
userIds: [{ | ||
name: 'gravitompId' | ||
}] | ||
} | ||
}); | ||
``` | ||
|
||
| Param under userSync.userIds[] | Scope | Type | Description | Example | | ||
| --- | --- | --- | --- | --- | | ||
| name | Required | String | The name of this module. | `"gravitompId"` | |
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 |
---|---|---|
|
@@ -166,6 +166,9 @@ pbjs.setConfig({ | |
}, | ||
{ | ||
name: "dacId" | ||
}, | ||
{ | ||
name: "gravitompId" | ||
} | ||
], | ||
syncDelay: 5000, | ||
|
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 { gravitoIdSystemSubmodule, storage, cookieKey } from 'modules/gravitoIdSystem.js'; | ||
|
||
const GRAVITOID_TEST_VALUE = 'gravitompIdTest'; | ||
const GRAVITOID_TEST_OBJ = { | ||
gravitompId: GRAVITOID_TEST_VALUE | ||
}; | ||
|
||
describe('gravitompId 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 gravitompId when it exists in cookie', function () { | ||
getCookieStub.withArgs(cookieKey).returns(GRAVITOID_TEST_VALUE); | ||
const id = gravitoIdSystemSubmodule.getId(); | ||
expect(id).to.be.deep.equal({id: {gravitompId: GRAVITOID_TEST_VALUE}}); | ||
}); | ||
|
||
cookieTestCasesForEmpty.forEach(testCase => it('should return the gravitompId when it not exists in cookie', function () { | ||
getCookieStub.withArgs(cookieKey).returns(testCase); | ||
const id = gravitoIdSystemSubmodule.getId(); | ||
expect(id).to.be.deep.equal(undefined); | ||
})); | ||
}); | ||
|
||
describe('decode()', function () { | ||
it('should return the gravitompId when it exists in cookie', function () { | ||
const decoded = gravitoIdSystemSubmodule.decode(GRAVITOID_TEST_OBJ); | ||
expect(decoded).to.be.deep.equal({gravitompId: {id: GRAVITOID_TEST_VALUE}}); | ||
}); | ||
|
||
it('should return the undefined when decode id is not "string"', function () { | ||
const decoded = gravitoIdSystemSubmodule.decode(1); | ||
expect(decoded).to.equal(undefined); | ||
}); | ||
}); | ||
}); |