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

update the PR comments #4

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
71 changes: 21 additions & 50 deletions modules/mwOpenLinkIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { getStorageManager } from '../src/storageManager.js';

var openLinkID = {
const openLinkID = {
name: 'mwol',
cookie_expiration: (86400 * 1000 * 365 * 3),
cookie_expiration: (86400 * 1000 * 365 * 1), // 1 year
value: ''
}

const storage = getStorageManager();
var configParams = {};

function getExpirationDate() {
const oneYearFromNow = new Date(utils.timestamp() + openLinkID.cookie_expiration);
Expand All @@ -30,16 +29,13 @@ function isValidConfig(configParams) {
return false;
}
if (!configParams.accountId) {
utils.logError('User ID - mwOlId submodule requires account Id to be defined');
utils.logError('User ID - mwOlId submodule requires accountId to be defined');
return false;
}
if (!configParams.partnerId) {
utils.logError('User ID - mwOlId submodule requires partner Id to be defined');
utils.logError('User ID - mwOlId submodule requires partnerId to be defined');
return false;
}
if (configParams.storage) {
utils.logWarn('User ID - mwOlId submodule does not require a storage config');
}
return true;
}

Expand Down Expand Up @@ -88,29 +84,9 @@ function writeCookie(mwOLId) {
}
}

/* MW */

function generateUUID() { // Public Domain/MIT
var d = new Date().getTime();// Timestamp
var d2 = (performance && performance.now && (performance.now() * 1000)) || 0;// Time in microseconds since page-load or 0 if unsupported
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16;// random number between 0 and 16
if (d > 0) { // Use timestamp until depleted
r = (d + r) % 16 | 0;
d = Math.floor(d / 16);
} else { // Use microseconds since page-load if supported
r = (d2 + r) % 16 | 0;
d2 = Math.floor(d2 / 16);
}
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}

function register(olid) {
var accountId = (configParams.accountId != 'undefined') ? configParams.accountId : '';
var partnerId = (configParams.partnerId != 'undefined') ? configParams.partnerId : '';
var uid = (configParams.uid != 'undefined') ? configParams.uid : '';
var url = 'https://ol.mediawallahscript.com/?account_id=' + accountId +
function register(configParams, olid) {
const { accountId, partnerId, uid } = configParams;
const url = 'https://ol.mediawallahscript.com/?account_id=' + accountId +
'&partner_id=' + partnerId +
'&uid=' + uid +
'&olid=' + olid +
Expand All @@ -120,28 +96,30 @@ function register(olid) {
}

function setID(configParams) {
if (!isValidConfig(configParams)) return;
if (!isValidConfig(configParams)) return undefined;

let mwOLId = readCookie();
openLinkID.value = generateUUID();
const mwOLId = readCookie();
openLinkID.value = utils.generateUUID();

let newmwOLId = mwOLId ? utils.deepClone(mwOLId) : {eid: openLinkID.value};
const newmwOLId = mwOLId ? utils.deepClone(mwOLId) : {eid: openLinkID.value};
writeCookie(newmwOLId);
register(newmwOLId.eid);
register(configParams, newmwOLId.eid);
return {
id: mwOLId
};
};

/* End MW */

export { writeCookie };

/** @type {Submodule} */
export const mwOpenLinkSubModule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'mwOlId',
name: 'mwOpenLinkId',
/**
* decode the stored id value for passing to bid requests
* @function
Expand All @@ -158,20 +136,13 @@ export const mwOpenLinkSubModule = {
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [configParams]
* @param {ConsentData} [consentData]
* @returns {function(callback:function), id:MwOlId}
* @param {SubmoduleParams} [submoduleParams]
* @returns {id:MwOlId | undefined}
*/
getId(configParams, consentData, currentStoredId) {
if (!isValidConfig(configParams)) return { id: undefined };
const hasGdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0;
const gdprConsentString = hasGdpr ? consentData.consentString : '';
// use protocol relative urls for http or https
if (hasGdpr && (!gdprConsentString || gdprConsentString === '')) {
utils.logInfo('Consent string is required to generate or retrieve ID.');
// return { id: undefined };
}
const newId = setID(configParams);
getId(submoduleConfig) {
const submoduleConfigParams = (submoduleConfig && submoduleConfig.params) || {};
if (!isValidConfig(submoduleConfigParams)) return undefined;
const newId = setID(submoduleConfigParams);
return newId;
}
};
Expand Down
21 changes: 5 additions & 16 deletions modules/mwOpenLinkIdSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@ When the module is included, it's automatically enabled and saves an id to both

### Prebid Params

Individual params may be set for the BritePool User ID Submodule. At least one identifier must be set in the params.
Individual params may be set for the MediaWallah openLink User ID Submodule. At least one identifier must be set in the params.
```
pbjs.setConfig({
userSync: {
userIds: [{
name: 'mwolid',
storage: {
name: 'mwol',
type: 'cookie',
expires: 3
},
name: 'mwOpenLinkId',
params: {
accountId: 0000,
partnerId: 0000,
uid: '12345xyz'

}
}]
}
Expand All @@ -40,12 +34,7 @@ The below parameters apply only to the MediaWallah OpenLink ID User ID Module in

| Params under usersync.userIds[]| Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | ID value for the Shared ID module - `"sharedId"` | `"sharedId"` |
| params | Required | Object | Details for mwOLID syncing. | |
| params.account_id | Required | String | The MediaWallah assigned Account Id | `1000` |
| params.partner_id | Required | String | The MediaWallah assign partner Id | `params.ssid` `params.aaid` |
| params.uid | Optional | String | Your unique Id for the user or browser. Used for matching| `u-123xyz` |
| storage | Required | Object | The publisher must specify the local storage in which to store the results of the call to get the user ID. This can be either cookie or HTML5 storage. | |
| storage.type | Required | String | This is where the results of the user ID will be stored. The recommended method is `localStorage` by specifying `html5`. | `"html5"` |
| storage.name | Required | String | The name of the cookie or html5 local storage where the user ID will be stored. | `"sharedid"` |
| storage.expires | Optional | Integer | How long (in years) the user ID information will be stored. | `1` |
| params.accountId | Required | String | The MediaWallah assigned Account Id | `1000` |
| params.partnerId | Required | String | The MediaWallah assign partner Id | `1001` |
| params.uid | Optional | String | Your unique Id for the user or browser. Used for matching| `u-123xyz` |
44 changes: 6 additions & 38 deletions test/spec/modules/mwOpenLinkIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,25 @@
import { mwOpenLinkSubModule } from 'modules/mwOpenLinkIdSystem.js';
import { newStorageManager } from 'src/storageManager.js';

const storage = newStorageManager();
import { writeCookie, mwOpenLinkSubModule } from 'modules/mwOpenLinkIdSystem.js';

const P_CONFIG_MOCK = {
params: {
accountId: '123',
partnerId: '123',
storage: true
partnerId: '123'
}
};

function serializeMWOLId(mwOLId) {
let components = [];

if (mwOLId.eid) {
components.push('eid:' + mwOLId.eid);
}
if (mwOLId.ibaOptout) {
components.push('ibaOptout:1');
}
if (mwOLId.ccpaOptout) {
components.push('ccpaOptout:1');
}

return components.join(',');
}

function writeMwOpenLinkIdCookie(name, mwOLId) {
if (mwOLId) {
const mwOLIdStr = encodeURIComponent(serializeMWOLId(mwOLId));
storage.setCookie(
name,
mwOLIdStr,
(new Date(Date.now() + 5000).toUTCString()),
'lax');
}
}

describe('mwOpenLinkId module', function () {
beforeEach(function() {
writeMwOpenLinkIdCookie('mwol', '');
writeCookie('');
});

it('getId() should return a MediaWallah openLink Id when the MediaWallah openLink first party cookie exists', function () {
writeMwOpenLinkIdCookie('mwol', {eid: 'XX-YY-ZZ-123'});

const id = mwOpenLinkSubModule.getId(P_CONFIG_MOCK.params, null, null);
writeCookie({eid: 'XX-YY-ZZ-123'});
const id = mwOpenLinkSubModule.getId(P_CONFIG_MOCK);
expect(id).to.be.deep.equal({id: {eid: 'XX-YY-ZZ-123'}});
});

it('getId() should return an empty Id when the MediaWallah openLink first party cookie is missing', function () {
const id = mwOpenLinkSubModule.getId();
expect(id).to.be.deep.equal({id: undefined});
expect(id).to.be.deep.equal(undefined);
});
});