Skip to content

Commit

Permalink
DMD ID System: add new User ID module (#6666)
Browse files Browse the repository at this point in the history
* feat(prebid): DMD UserID Module reading from 1st party cookie [PREBID-1]

* feat(prebid):additional parameter[PREB-1]

* feat(prebid):update decode function and cacheobi[PREB-1]

* test(prebid):added more test coverage[PREB-11]

* feat(typo):cleared typo[PREB-11]

* test(prebid):updated test cases[PREB-11]

* feat(releasenote):added a release note[PREB-11]

* fix(releasenote):removed unnecessary release note[PREB-11]

* fix(test):updated failing test cases[PREB-11]

Co-authored-by: Matt Fitzgerald <matthewfitz@gmail.com>
Co-authored-by: Karthik Boppudi <kboppudi@kboppudimac0518.local>
Co-authored-by: mfitzgerald_dmd <mfitzgerald@dmdconnects.com>
  • Loading branch information
4 people authored and idettman committed May 21, 2021
1 parent bd38efb commit 07e5437
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 16 deletions.
3 changes: 2 additions & 1 deletion modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"tapadIdSystem",
"novatiqIdSystem",
"uid2IdSystem",
"admixerIdSystem"
"admixerIdSystem",
"dmdIdSystem"
],
"adpod": [
"freeWheelAdserverVideo",
Expand Down
58 changes: 58 additions & 0 deletions modules/dmdIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* This module adds dmdId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/dmdIdSystem
* @requires module:modules/userId
*/

import * as utils from '../src/utils.js';
import { submodule } from '../src/hook.js';

/** @type {Submodule} */
export const dmdIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'dmdId',

/**
* decode the stored id value for passing to bid requests
* @function decode
* @param {(Object|string)} value
* @returns {(Object|undefined)}
*/
decode(value) {
return value && typeof value === 'string'
? { 'dmdId': value }
: undefined;
},

/**
* performs action to obtain id and return a value in the callback's response argument
* @function getId
* @param {SubmoduleConfig} [config]
* @param {ConsentData}
* @param {Object} cacheIdObj - existing id, if any consentData]
* @returns {IdResponse|undefined}
*/
getId(config, consentData, cacheIdObj) {
try {
const configParams = (config && config.params) || {};
if (
!configParams ||
!configParams.api_key ||
typeof configParams.api_key !== 'string'
) {
utils.logError('dmd submodule requires an api_key.');
return;
} else {
return cacheIdObj;
}
} catch (e) {
utils.logError(`dmdIdSystem encountered an error`, e);
}
},
};

submodule('userId', dmdIdSubmodule);
26 changes: 26 additions & 0 deletions modules/dmdIdSystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pbjs.setConfig({
userSync: {
userIds: [{
name: 'dmdId',
storage: {
name: 'dmd-dgid',
type: 'cookie',
expires: 30
},
params: {
api_key: '3fdbe297-3690-4f5c-9e11-ee9186a6d77c', // provided by DMD
}
}]
}
});

#### DMD ID Configuration

{: .table .table-bordered .table-striped }
| Param under userSync.userIds[] | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | The name of Module | `"dmdId"` |
| storage | Required | Object | |
| storage.name | Required | String | `dmd-dgid` |
| params | Required | Object | Container of all module params. | |
| params.api_key | Required | String | This is your `api_key` as provided by DMD Marketing Corp. | `3fdbe297-3690-4f5c-9e11-ee9186a6d77c` |
6 changes: 6 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ const USER_IDS_CONFIG = {
atype: 3
},

// dmdId
'dmdId': {
source: 'hcn.health',
atype: 3
},

// lotamePanoramaId
lotamePanoramaId: {
source: 'crwdcntrl.net',
Expand Down
8 changes: 8 additions & 0 deletions modules/userId/eids.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ userIdAsEids = [
}]
},
{
source: 'hcn.health',
uids: [{
id: 'some-random-id-value',
atype: 3
}]
},
{
source: 'criteo.com',
uids: [{
Expand Down
10 changes: 10 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ pbjs.setConfig({
name: "_pubcid",
expires: 60
}
}, {
name: 'dmdId',
storage: {
name: 'dmd-dgid',
type: 'cookie',
expires: 30
},
params: {
api_key: '3fdbe297-3690-4f5c-9e11-ee9186a6d77c', // provided by DMD
}
}, {
name: "unifiedId",
params: {
Expand Down
48 changes: 48 additions & 0 deletions test/spec/modules/dmdIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as utils from '../../../src/utils.js';

import {dmdIdSubmodule} from 'modules/dmdIdSystem.js';

describe('Dmd ID System', function() {
let logErrorStub;

beforeEach(function () {
logErrorStub = sinon.stub(utils, 'logError');
});

afterEach(function () {
logErrorStub.restore();
});

it('should log an error if no configParams were passed into getId', function () {
dmdIdSubmodule.getId();
expect(logErrorStub.calledOnce).to.be.true;
});

it('should log an error if configParams doesnot have api_key passed to getId', function () {
dmdIdSubmodule.getId({params: {}});
expect(logErrorStub.calledOnce).to.be.true;
});

it('should log an error if configParams has invalid api_key passed into getId', function () {
dmdIdSubmodule.getId({params: {api_key: 123}});
expect(logErrorStub.calledOnce).to.be.true;
});

it('should not log an error if configParams has valid api_key passed into getId', function () {
dmdIdSubmodule.getId({params: {api_key: '3fdbe297-3690-4f5c-9e11-ee9186a6d77c'}});
expect(logErrorStub.calledOnce).to.be.false;
});

it('should return undefined if empty value passed into decode', function () {
expect(dmdIdSubmodule.decode()).to.be.undefined;
});

it('should return undefined if invalid dmd-dgid passed into decode', function () {
expect(dmdIdSubmodule.decode(123)).to.be.undefined;
});

it('should return dmdId if valid dmd-dgid passed into decode', function () {
let data = { 'dmdId': 'U12345' };
expect(dmdIdSubmodule.decode('U12345')).to.deep.equal(data);
});
});
Loading

0 comments on commit 07e5437

Please sign in to comment.