-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Isaac Dettman
committed
May 17, 2019
1 parent
ad7b59d
commit 642abb2
Showing
5 changed files
with
464 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); | ||
} | ||
} | ||
}; |
Oops, something went wrong.