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

Intimate Merger Universal Identifier System: add imuid submodule #7239

Merged
merged 3 commits into from
Aug 11, 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
6 changes: 6 additions & 0 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@
// To get new token, register https://developer.chrome.com/origintrials/#/trials/active for Federated Learning of Cohorts
token: "A3dHTSoNUMjjERBLlrvJSelNnwWUCwVQhZ5tNQ+sll7y+LkPPVZXtB77u2y7CweRIxiYaGwGXNlW1/dFp8VMEgIAAAB+eyJvcmlnaW4iOiJodHRwczovL3NoYXJlZGlkLm9yZzo0NDMiLCJmZWF0dXJlIjoiSW50ZXJlc3RDb2hvcnRBUEkiLCJleHBpcnkiOjE2MjYyMjA3OTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"
}
},
{
"name": "imuid",
"params": {
"cid": 5126 // Set your Intimate Merger Customer ID here for production
}
}
],
"syncDelay": 5000,
"auctionDelay": 1000
Expand Down
3 changes: 2 additions & 1 deletion modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"dmdIdSystem",
"akamaiDAPId",
"flocIdSystem",
"amxIdSystem"
"amxIdSystem",
"imuIdSystem"
],
"adpod": [
"freeWheelAdserverVideo",
Expand Down
151 changes: 151 additions & 0 deletions modules/imuIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* The {@link module:modules/userId} module is required
* @module modules/imuIdSystem
*
* @requires module:modules/userId
*/

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

export const storage = getStorageManager();

export const storageKey = '__im_uid';
export const cookieKey = '_im_vid';
export const apiUrl = 'https://audiencedata.im-apps.net/imuid/get';
const storageMaxAge = 1800000; // 30 minites (30 * 60 * 1000)
const cookiesMaxAge = 97200000000; // 37 months ((365 * 3 + 30) * 24 * 60 * 60 * 1000)

export function setImDataInLocalStorage(value) {
storage.setDataInLocalStorage(storageKey, value);
storage.setDataInLocalStorage(`${storageKey}_mt`, new Date(utils.timestamp()).toUTCString());
}

export function removeImDataFromLocalStorage() {
storage.removeDataFromLocalStorage(storageKey);
storage.removeDataFromLocalStorage(`${storageKey}_mt`);
}

function setImDataInCookie(value) {
storage.setCookie(
cookieKey,
value,
new Date(utils.timestamp() + cookiesMaxAge).toUTCString(),
'none'
);
}

export function getLocalData() {
const mt = storage.getDataFromLocalStorage(`${storageKey}_mt`);
let expired = true;
if (Date.parse(mt) && Date.now() - (new Date(mt)).getTime() < storageMaxAge) {
expired = false;
}
return {
id: storage.getDataFromLocalStorage(storageKey),
vid: storage.getCookie(cookieKey),
expired: expired
};
}

export function apiSuccessProcess(jsonResponse) {
if (!jsonResponse) {
return;
}
if (jsonResponse.uid) {
setImDataInLocalStorage(jsonResponse.uid);
if (jsonResponse.vid) {
setImDataInCookie(jsonResponse.vid);
}
} else {
removeImDataFromLocalStorage();
}
}

export function getApiCallback(callback) {
return {
success: response => {
let responseObj = {};
if (response) {
try {
responseObj = JSON.parse(response);
apiSuccessProcess(responseObj);
} catch (error) {
utils.logError('User ID - imuid submodule: ' + error);
}
}
if (callback && responseObj.uid) {
callback(responseObj.uid);
}
},
error: error => {
utils.logError('User ID - imuid submodule was unable to get data from api: ' + error);
if (callback) {
callback();
}
}
};
}

export function callImuidApi(apiUrl) {
return function (callback) {
ajax(apiUrl, getApiCallback(callback), undefined, {method: 'GET', withCredentials: true});
};
}

export function getApiUrl(cid, url) {
if (url) {
return `${url}?cid=${cid}`;
}
return `${apiUrl}?cid=${cid}`;
}

/** @type {Submodule} */
export const imuIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'imuid',
/**
* decode the stored id value for passing to bid requests
* @function
* @returns {{imuid: string} | undefined}
*/
decode(id) {
if (id && typeof id === 'string') {
return {imuid: id};
}
return undefined;
},
/**
* @function
* @param {SubmoduleConfig} [config]
* @returns {{id: string} | undefined | {callback:function}}}
*/
getId(config) {
const configParams = (config && config.params) || {};
if (!configParams || typeof configParams.cid !== 'number') {
utils.logError('User ID - imuid submodule requires a valid cid to be defined');
return undefined;
}
let apiUrl = getApiUrl(configParams.cid, configParams.url);
const localData = getLocalData();
if (localData.vid) {
apiUrl += `&vid=${localData.vid}`;
setImDataInCookie(localData.vid);
}

if (!localData.id) {
return {callback: callImuidApi(apiUrl)}
}
if (localData.expired) {
callImuidApi(apiUrl)();
}
return {id: localData.id};
}
};

submodule('userId', imuIdSubmodule);
35 changes: 35 additions & 0 deletions modules/imuIdSystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Intimate Merger User ID Submodule

IM-UID is a universal identifier provided by Intimate Merger.
The integration of [IM-UID](https://intimatemerger.com/r/uid) into Prebid.js consists of this module.

## Building Prebid with IM-UID Support

First, make sure to add the Intimate Merger submodule to your Prebid.js package with:

```
gulp build --modules=imuIdSystem, userId
```

The following configuration parameters are available:

```javascript
pbjs.setConfig({
userSync: {
userIds: [{
name: 'imuid',
params: {
cid 5126 // Set your Intimate Merger Customer ID here for production
}
}
}]
}
});
```

| Param under userSync.userIds[] | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | The name of this module. | `"imuid"` |
| params | Required | Object | Details of module params. | |
| params.cid | Required | String | This is the Customer ID value obtained via Intimate Merger. | `5126` |
| params.url | Optional | String | Use this to change the default endpoint URL. | `"https://example.com/some/api"` |
4 changes: 4 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ const USER_IDS_CONFIG = {
amxId: {
source: 'amxrtb.com',
atype: 1,
},
'imuid': {
source: 'intimatemerger.com',
atype: 1
}
};

Expand Down
6 changes: 6 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ pbjs.setConfig({
name: "_dpes_id",
expires: 90
}
},
{
name: 'imuid',
params: {
cid: 5126 // Set your Intimate Merger Customer ID here for production
}
}],
syncDelay: 5000
}
Expand Down
Loading