Skip to content

Commit

Permalink
Navegg UserId: add new userid submodule (prebid#7123)
Browse files Browse the repository at this point in the history
* navegg userid

* remove unused variable results

* fix submodules json

* unit test to find navegg id

* Adjustments according to revision

* new unit tests

* add akamai module

* add akamai module
  • Loading branch information
hugopenha-navegg authored and Chris Pabst committed Jan 10, 2022
1 parent d92bd98 commit 89d1586
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 8 deletions.
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"akamaiDAPId",
"flocIdSystem",
"amxIdSystem",
"naveggId",
"imuIdSystem"
],
"adpod": [
Expand Down
90 changes: 90 additions & 0 deletions modules/naveggIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* This module adds naveggId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/naveggId
* @requires module:modules/userId
*/
import * as utils from '../src/utils.js'
import { submodule } from '../src/hook.js';
import { getStorageManager } from '../src/storageManager.js';

const MODULE_NAME = 'naveggId';
const OLD_NAVEGG_ID = 'nid';
const NAVEGG_ID = 'nvggid'

export const storage = getStorageManager();

function readnaveggIdFromLocalStorage() {
return storage.getDataFromLocalStorage(NAVEGG_ID);
}

function readnaveggIDFromCookie() {
return storage.cookiesAreEnabled ? storage.getCookie(NAVEGG_ID) : null;
}

function readoldnaveggIDFromCookie() {
return storage.cookiesAreEnabled ? storage.getCookie(OLD_NAVEGG_ID) : null;
}

function readnvgIDFromCookie() {
return storage.cookiesAreEnabled ? (storage.findSimilarCookies('nvg') ? storage.findSimilarCookies('nvg')[0] : null) : null;
}

function readnavIDFromCookie() {
return storage.cookiesAreEnabled ? (storage.findSimilarCookies('nav') ? storage.findSimilarCookies('nav')[0] : null) : null;
}

function readnvgnavFromLocalStorage() {
var i;
const query = '^nvg|^nav';
for (i in window.localStorage) {
if (i.match(query) || (!query && typeof i === 'string')) {
return storage.getDataFromLocalStorage(i.match(query).input);
}
}
}

/** @type {Submodule} */
export const naveggIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,
/**
* decode the stored id value for passing to bid requests
* @function
* @param { Object | string | undefined } value
* @return { Object | string | undefined }
*/
decode(value) {
const naveggIdVal = value ? utils.isStr(value) ? value : utils.isPlainObject(value) ? value.id : undefined : undefined;
return naveggIdVal ? {
'naveggId': naveggIdVal
} : undefined;
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleConfig} config
* @return {{id: string | undefined } | undefined}
*/
getId() {
let naveggIdStringFromLocalStorage = null;
if (storage.localStorageIsEnabled) {
naveggIdStringFromLocalStorage = readnaveggIdFromLocalStorage() || readnvgnavFromLocalStorage();
}

const naveggIdString = naveggIdStringFromLocalStorage || readnaveggIDFromCookie() || readoldnaveggIDFromCookie() || readnvgIDFromCookie() || readnavIDFromCookie();

if (typeof naveggIdString == 'string' && naveggIdString) {
try {
return { id: naveggIdString };
} catch (error) {
utils.logError(error);
}
}
return undefined;
}
};
submodule('userId', naveggIdSubmodule);
22 changes: 22 additions & 0 deletions modules/naveggIdSystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Navegg User ID Submodule

For assistance setting up your module please contact us at [[email protected]]([email protected]).

### Prebid Params

Individual params may be set for the IDx Submodule.
```
pbjs.setConfig({
userSync: {
userIds: [{
name: 'naveggId',
}]
}
});
```
## Parameter Descriptions for the `userSync` Configuration Section
The below parameters apply only to the naveggID integration.

| Param under usersync.userIds[] | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | ID of the module - `"naveggId"` | `"naveggId"` |
14 changes: 10 additions & 4 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const USER_IDS_CONFIG = {
atype: 1
},

// naveggId
'naveggId': {
source: 'navegg.com',
atype: 1
},

// pubCommonId
'pubcid': {
source: 'pubcid.org',
Expand Down Expand Up @@ -199,15 +205,15 @@ const USER_IDS_CONFIG = {
return data.id;
}
},
'deepintentId': {
source: 'deepintent.com',
atype: 3
},
// Akamai Data Activation Platform (DAP)
'dapId': {
source: 'akamai.com',
atype: 1
},
'deepintentId': {
source: 'deepintent.com',
atype: 3
},
// Admixer Id
'admixerId': {
source: 'admixer.net',
Expand Down
16 changes: 12 additions & 4 deletions modules/userId/eids.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ userIdAsEids = [
}]
},
{
source: 'navegg.com',
uids: [{
id: 'naveggId',
atype: 1
}]
},
{
source: 'neustar.biz',
uids: [{
Expand Down Expand Up @@ -176,17 +184,17 @@ userIdAsEids = [
}]
},
{
source: 'admixer.net',
source: 'akamai.com',
uids: [{
id: 'some-random-id-value',
atype: 3
atype: 1
}]
},
{
source: 'akamai.com',
source: 'admixer.net',
uids: [{
id: 'some-random-id-value',
atype: 1
atype: 3
}]
},
{
Expand Down
3 changes: 3 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ pbjs.setConfig({
{
name: "novatiq",
value: { "snowflake": "81b001ec-8914-488c-a96e-8c220d4ee08895ef" }
},
{
name: 'naveggId',
}],
syncDelay: 5000
}
Expand Down
21 changes: 21 additions & 0 deletions test/spec/modules/naveggIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { naveggIdSubmodule, storage } from 'modules/naveggIdSystem.js';

describe('naveggId', function () {
it('should NOT find navegg id', function () {
let id = naveggIdSubmodule.getId();

expect(id).to.be.undefined;
});

it('getId() should return "test-nid" id from cookie OLD_NAVEGG_ID', function() {
sinon.stub(storage, 'getCookie').withArgs('nid').returns('test-nid');
let id = naveggIdSubmodule.getId();
expect(id).to.be.deep.equal({id: 'test-nid'})
})

it('getId() should return "test-nvggid" id from local storage NAVEGG_ID', function() {
sinon.stub(storage, 'getDataFromLocalStorage').withArgs('nvggid').returns('test-ninvggidd');
let id = naveggIdSubmodule.getId();
expect(id).to.be.deep.equal({id: 'test-ninvggidd'})
})
});

0 comments on commit 89d1586

Please sign in to comment.