Skip to content

Commit

Permalink
support external userId sub-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Dettman committed May 17, 2019
1 parent ad7b59d commit 642abb2
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 282 deletions.
42 changes: 42 additions & 0 deletions modules/pubCommonIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* This module adds PubCommonId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/pubCommonIdSystem
* @requires module:modules/userId
*/

import * as utils from '../src/utils.js'

/** @type {Submodule} */
export const pubCommonIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'pubCommonId',
/**
* decode the stored id value for passing to bid requests
* @function
* @param {string} value
* @returns {{pubcid:string}}
*/
decode(value) {
return { 'pubcid': value }
},
/**
* performs action to obtain id
* @function
* @returns {string}
*/
getId() {
// If the page includes its own pubcid object, then use that instead.
let pubcid;
try {
if (typeof window['PublisherCommonId'] === 'object') {
pubcid = window['PublisherCommonId'].getId();
}
} catch (e) {}
// check pubcid and return if valid was otherwise create a new id
return (pubcid) || utils.generateUUID();
}
};
55 changes: 55 additions & 0 deletions modules/unifiedIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* This module adds UnifiedId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/unifiedIdSystem
* @requires module:modules/userId
*/

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

/** @type {Submodule} */
export const unifiedIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'unifiedId',
/**
* decode the stored id value for passing to bid requests
* @function
* @param {{TDID:string}} value
* @returns {{tdid:Object}}
*/
decode(value) {
return (value && typeof value['TDID'] === 'string') ? { 'tdid': value['TDID'] } : undefined;
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [configParams]
* @returns {function(callback:function)}
*/
getId(configParams) {
if (!configParams || (typeof configParams.partner !== 'string' && typeof configParams.url !== 'string')) {
utils.logError('User ID - unifiedId submodule requires either partner or url to be defined');
return;
}
// use protocol relative urls for http or https
const url = configParams.url || `//match.adsrvr.org/track/rid?ttd_pid=${configParams.partner}&fmt=json`;

return function (callback) {
ajax(url, response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
}, undefined, { method: 'GET' });
}
}
};
Loading

0 comments on commit 642abb2

Please sign in to comment.