From ffcd2ec9775a324a5fcd9392cb3715f1e9ef3787 Mon Sep 17 00:00:00 2001 From: rahulgravito Date: Mon, 16 May 2022 10:07:18 +0530 Subject: [PATCH 1/3] gravitompId user module for integrating gravito first party cookie with prebid js --- integrationExamples/gpt/userId_example.html | 3 ++ modules/.submodules.json | 3 +- modules/gravitoIdSystem.js | 58 +++++++++++++++++++++ modules/gravitoIdSystem.md | 28 ++++++++++ modules/userId/eids.js | 6 +++ modules/userId/userId.md | 3 ++ test/spec/modules/gravitoIdSystem_spec.js | 51 ++++++++++++++++++ 7 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 modules/gravitoIdSystem.js create mode 100644 modules/gravitoIdSystem.md create mode 100644 test/spec/modules/gravitoIdSystem_spec.js diff --git a/integrationExamples/gpt/userId_example.html b/integrationExamples/gpt/userId_example.html index 52578ebcada..4bba558c4db 100644 --- a/integrationExamples/gpt/userId_example.html +++ b/integrationExamples/gpt/userId_example.html @@ -267,6 +267,9 @@ }, { "name": "dacId" + }, + { + "name": "gravitompId" } ], "syncDelay": 5000, diff --git a/modules/.submodules.json b/modules/.submodules.json index 59bae2013d1..9402d0561fa 100644 --- a/modules/.submodules.json +++ b/modules/.submodules.json @@ -43,7 +43,8 @@ "unifiedIdSystem", "verizonMediaIdSystem", "zeotapIdPlusIdSystem", - "adqueryIdSystem" + "adqueryIdSystem", + "gravitoIdSystem" ], "adpod": [ "freeWheelAdserverVideo", diff --git a/modules/gravitoIdSystem.js b/modules/gravitoIdSystem.js new file mode 100644 index 00000000000..5f5eebe7277 --- /dev/null +++ b/modules/gravitoIdSystem.js @@ -0,0 +1,58 @@ +/** + * 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); + \ No newline at end of file diff --git a/modules/gravitoIdSystem.md b/modules/gravitoIdSystem.md new file mode 100644 index 00000000000..af4946779c5 --- /dev/null +++ b/modules/gravitoIdSystem.md @@ -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"` | diff --git a/modules/userId/eids.js b/modules/userId/eids.js index 9c995a52fe3..b5b57343b07 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -314,6 +314,12 @@ export const USER_IDS_CONFIG = { return data.envelope; } }, + + // Gravito MP ID + 'gravitompId': { + source: 'gravito.net', + atype: 1 + }, }; // this function will create an eid object for the given UserId sub-module diff --git a/modules/userId/userId.md b/modules/userId/userId.md index ed5b0adcd71..3b99780b39e 100644 --- a/modules/userId/userId.md +++ b/modules/userId/userId.md @@ -166,6 +166,9 @@ pbjs.setConfig({ }, { name: "dacId" + }, + { + name: "gravitompId" } ], syncDelay: 5000, diff --git a/test/spec/modules/gravitoIdSystem_spec.js b/test/spec/modules/gravitoIdSystem_spec.js new file mode 100644 index 00000000000..e904355f7f1 --- /dev/null +++ b/test/spec/modules/gravitoIdSystem_spec.js @@ -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); + }); + }); +}); From ab47202634f2a8896b43dcf4337a27631f3a02d7 Mon Sep 17 00:00:00 2001 From: rahulgravito Date: Mon, 16 May 2022 13:06:16 +0530 Subject: [PATCH 2/3] fixed eslint issues raised by circleci --- modules/gravitoIdSystem.js | 99 +++++++++++++++++++------------------- modules/userId/eids.js | 4 +- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/modules/gravitoIdSystem.js b/modules/gravitoIdSystem.js index 5f5eebe7277..1b56dafe162 100644 --- a/modules/gravitoIdSystem.js +++ b/modules/gravitoIdSystem.js @@ -5,54 +5,53 @@ * @requires module:modules/userId */ - import { submodule } from '../src/hook.js'; - import { getStorageManager } from '../src/storageManager.js'; +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); - \ No newline at end of file +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); diff --git a/modules/userId/eids.js b/modules/userId/eids.js index b5b57343b07..2f076088c3e 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -315,8 +315,8 @@ export const USER_IDS_CONFIG = { } }, - // Gravito MP ID - 'gravitompId': { + // Gravito MP ID + 'gravitompId': { source: 'gravito.net', atype: 1 }, From f798f4b7464ac72cd49a3d55622ade6c529b5a0e Mon Sep 17 00:00:00 2001 From: rahulgravito Date: Mon, 16 May 2022 13:10:55 +0530 Subject: [PATCH 3/3] fixed trailing spaces error raised by circleci --- modules/gravitoIdSystem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gravitoIdSystem.js b/modules/gravitoIdSystem.js index 1b56dafe162..30fa3abd6d2 100644 --- a/modules/gravitoIdSystem.js +++ b/modules/gravitoIdSystem.js @@ -7,7 +7,7 @@ import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; - + export const storage = getStorageManager(); export const cookieKey = 'gravitompId';