Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dacid User Id Module: add new id module #8187

Merged
merged 3 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@
"params": {
"cid": 5126 // Set your Intimate Merger Customer ID here for production
}
},
{
"name": "dacId"
}
],
"syncDelay": 5000,
Expand Down
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"britepoolIdSystem",
"connectIdSystem",
"criteoIdSystem",
"dacIdSystem",
"deepintentDpesIdSystem",
"dmdIdSystem",
"fabrickIdSystem",
Expand Down
57 changes: 57 additions & 0 deletions modules/dacIdSystem.js
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};
smenzer marked this conversation as resolved.
Show resolved Hide resolved
},

/**
* 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);
25 changes: 25 additions & 0 deletions modules/dacIdSystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## DAC User ID Submodule

## Building Prebid with DAC ID Support

First, make sure to add the DAC ID submodule to your Prebid.js package with:
smenzer marked this conversation as resolved.
Show resolved Hide resolved

```
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"` |
6 changes: 6 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ const USER_IDS_CONFIG = {
source: 'adquery.io',
atype: 1
},

// DAC ID
'dacId': {
source: 'dac.co.jp',
atype: 1
},
};

// this function will create an eid object for the given UserId sub-module
Expand Down
3 changes: 3 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ pbjs.setConfig({
name: "knssoId",
expires: 30
},
{
name: "dacId"
}
],
syncDelay: 5000,
auctionDelay: 1000
Expand Down
51 changes: 51 additions & 0 deletions test/spec/modules/dacIdSystem_spec.js
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);
});
});
});