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

Novatiq ID System: allow configuration of the sync URL & allow callbacks for specific custom integrations #8089

Merged
merged 23 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
18d1849
Novatiq snowflake userId submodule
Feb 23, 2021
2a8ccd5
change request updates
Feb 24, 2021
1b41398
Update novatiqIdSystem_spec.js
Feb 24, 2021
65b7592
Update novatiqIdSystem.md
Mar 2, 2021
0d5b439
Merge branch 'prebid_master' into merge_latest
rajsidhunovatiq Jan 20, 2022
ae8b5ce
Merge pull request #2 from novatiq/merge_latest
rajsidhunovatiq Jan 20, 2022
efa7915
use the sharedId if available and configured
rajsidhunovatiq Jan 31, 2022
829655e
updated docs
rajsidhunovatiq Jan 31, 2022
72ccd50
test changes
rajsidhunovatiq Jan 31, 2022
1ac92f9
Merge pull request #3 from novatiq/sharedID
rajsidhunovatiq Jan 31, 2022
11c2e65
Merge branch 'prebid:master' into master
rajsidhunovatiq Jan 31, 2022
82245a5
defensive code not required
rajsidhunovatiq Feb 1, 2022
2651b19
Use the prebid storage manager instead of using native functions
rajsidhunovatiq Feb 10, 2022
c105b51
doc changes
rajsidhunovatiq Feb 10, 2022
ae006d8
trailing spaces
rajsidhunovatiq Feb 10, 2022
ef193ab
Merge branch 'prebid:master' into master
rajsidhunovatiq Feb 14, 2022
c9a0003
Merge branch 'prebid:master' into master
rajsidhunovatiq Feb 18, 2022
172b694
Allow configuration of the sync URL and to allow callbacks for specif…
rajsidhunovatiq Feb 18, 2022
c90d36c
update documentation
rajsidhunovatiq Feb 18, 2022
361d5ed
Merge branch 'prebid:master' into master
rajsidhunovatiq Feb 18, 2022
996f8c9
attempt to fix firefox test timeout
rajsidhunovatiq Feb 18, 2022
b896067
Merge branch 'master' of https://github.com/novatiq/Prebid.js
rajsidhunovatiq Feb 18, 2022
d039277
Merge branch 'master' of https://github.com/prebid/Prebid.js
rajsidhunovatiq Mar 7, 2022
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
181 changes: 143 additions & 38 deletions modules/novatiqIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* @requires module:modules/userId
*/

import { logInfo } from '../src/utils.js';
import { logInfo, getWindowLocation } from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js';
import { getStorageManager } from '../src/storageManager.js';

/** @type {Submodule} */
export const novatiqIdSubmodule = {
Expand Down Expand Up @@ -40,60 +40,168 @@ export const novatiqIdSubmodule = {
* @returns {id: string}
*/
getId(config) {
function snowflakeId(placeholder) {
return placeholder
? (placeholder ^ Math.random() * 16 >> placeholder / 4).toString(16)
: ([1e7] + -1e3 + -4e3 + -8e3 + -1e11 + 1e3).replace(/[018]/g, snowflakeId);
}

const configParams = config.params || {};
const srcId = this.getSrcId(configParams);
const urlParams = this.getUrlParams(configParams);
const srcId = this.getSrcId(configParams, urlParams);
const sharedId = this.getSharedId(configParams);
const useCallbacks = this.useCallbacks(configParams);

logInfo('NOVATIQ config params: ' + JSON.stringify(configParams));
logInfo('NOVATIQ Sync request used sourceid param: ' + srcId);
logInfo('NOVATIQ Sync request Shared ID: ' + sharedId);

let partnerhost;
partnerhost = window.location.hostname;
logInfo('NOVATIQ partner hostname: ' + partnerhost);

const novatiqId = snowflakeId();
return this.sendSyncRequest(useCallbacks, sharedId, srcId, urlParams);
},

let url = 'https://spadsync.com/sync?sptoken=' + novatiqId + '&sspid=' + srcId + '&ssphost=' + partnerhost;
sendSyncRequest(useCallbacks, sharedId, sspid, urlParams) {
const syncUrl = this.getSyncUrl(sharedId, sspid, urlParams);
const url = syncUrl.url;
const novatiqId = syncUrl.novatiqId;

// for testing
let sharedStatus = 'Not Found';
const sharedStatus = (sharedId != undefined && sharedId != false) ? 'Found' : 'Not Found';

if (useCallbacks) {
let res = this.sendAsyncSyncRequest(novatiqId, url); ;
res.sharedStatus = sharedStatus;

return res;
} else {
this.sendSimpleSyncRequest(novatiqId, url);

return { 'id': novatiqId,
'sharedStatus': sharedStatus }
}
},

sendAsyncSyncRequest(novatiqId, url) {
logInfo('NOVATIQ Setting up ASYNC sync request');

const resp = function (callback) {
logInfo('NOVATIQ *** Calling ASYNC sync request');

function onSuccess(response, responseObj) {
let syncrc;
var novatiqIdJson = { syncResponse: 0 };
syncrc = responseObj.status;
logInfo('NOVATIQ Sync Response Code:' + syncrc);
logInfo('NOVATIQ *** ASYNC request returned ' + syncrc);
if (syncrc === 200) {
novatiqIdJson = { 'id': novatiqId, syncResponse: 1 };
} else {
if (syncrc === 204) {
novatiqIdJson = { 'id': novatiqId, syncResponse: 2 };
}
}
callback(novatiqIdJson);
}

ajax(url,
{ success: onSuccess },
undefined, { method: 'GET', withCredentials: false });
}

return {callback: resp};
},

sendSimpleSyncRequest(novatiqId, url) {
logInfo('NOVATIQ Sending SIMPLE sync request');

ajax(url, undefined, undefined, { method: 'GET', withCredentials: false });

logInfo('NOVATIQ snowflake: ' + novatiqId);
},

getNovatiqId(urlParams) {
// standard uuid format
let uuidFormat = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
if (urlParams.useStandardUuid == false) {
// novatiq standard uuid(like) format
uuidFormat = uuidFormat + 1e3;
}

return (uuidFormat).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
},

getSyncUrl(sharedId, sspid, urlParams) {
let novatiqId = this.getNovatiqId(urlParams);

let url = 'https://spadsync.com/sync?' + urlParams.novatiqId + '=' + novatiqId;

if (urlParams.useSspId) {
url = url + '&sspid=' + sspid;
}

if (urlParams.useSspHost) {
let ssphost = getWindowLocation().hostname;
logInfo('NOVATIQ partner hostname: ' + ssphost);

url = url + '&ssphost=' + ssphost;
}

// append on the shared ID if we have one
if (sharedId != null) {
url = url + '&sharedId=' + sharedId;
sharedStatus = 'Found';
}

ajax(url, undefined, undefined, { method: 'GET', withCredentials: false });
return {
url: url,
novatiqId: novatiqId
}
},

logInfo('NOVATIQ snowflake: ' + novatiqId);
return { 'id': novatiqId,
'sharedStatus': sharedStatus }
getUrlParams(configParams) {
let urlParams = {
novatiqId: 'snowflake',
useStandardUuid: false,
useSspId: true,
useSspHost: true
}

if (typeof configParams.urlParams != 'undefined') {
if (configParams.urlParams.novatiqId != undefined) {
urlParams.novatiqId = configParams.urlParams.novatiqId;
}
if (configParams.urlParams.useStandardUuid != undefined) {
urlParams.useStandardUuid = configParams.urlParams.useStandardUuid;
}
if (configParams.urlParams.useSspId != undefined) {
urlParams.useSspId = configParams.urlParams.useSspId;
}
if (configParams.urlParams.useSspHost != undefined) {
urlParams.useSspHost = configParams.urlParams.useSspHost;
}
}

return urlParams;
},

useCallbacks(configParams) {
return typeof configParams.useCallbacks != 'undefined' && configParams.useCallbacks === true;
},

useSharedId(configParams) {
return typeof configParams.useSharedId != 'undefined' && configParams.useSharedId === true;
},

getCookieOrStorageID(configParams) {
let cookieOrStorageID = '_pubcid';

if (typeof configParams.sharedIdName != 'undefined' && configParams.sharedIdName != null && configParams.sharedIdName != '') {
cookieOrStorageID = configParams.sharedIdName;
logInfo('NOVATIQ sharedID name redefined: ' + cookieOrStorageID);
}

return cookieOrStorageID;
},

// return null if we aren't supposed to use one or we are but there isn't one present
getSharedId(configParams) {
let sharedId = null;
if (this.useSharedId(configParams)) {
let cookieOrStorageID = '_pubcid';

// Has the cookieOrStorageID been redefined?
if (typeof configParams.sharedIdName != 'undefined' && configParams.sharedIdName != null && configParams.sharedIdName != '') {
cookieOrStorageID = configParams.sharedIdName;
logInfo('NOVATIQ sharedID name redefined: ' + cookieOrStorageID);
}

let cookieOrStorageID = this.getCookieOrStorageID(configParams);
const storage = getStorageManager({moduleName: 'pubCommonId'});

// first check local storage
Expand All @@ -114,24 +222,21 @@ export const novatiqIdSubmodule = {
return sharedId;
},

getSrcId(configParams) {
logInfo('NOVATIQ Configured sourceid param: ' + configParams.sourceid);

function isHex(str) {
var a = parseInt(str, 16);
return (a.toString(16) === str)
getSrcId(configParams, urlParams) {
if (urlParams.useSspId == false) {
logInfo('NOVATIQ Configured to NOT use sspid');
return '';
}

logInfo('NOVATIQ Configured sourceid param: ' + configParams.sourceid);

let srcId;
if (typeof configParams.sourceid === 'undefined' || configParams.sourceid === null || configParams.sourceid === '') {
srcId = '000';
logInfo('NOVATIQ sourceid param set to value 000 due to undefined parameter or missing value in config section');
} else if (configParams.sourceid.length < 3 || configParams.sourceid.length > 3) {
srcId = '001';
logInfo('NOVATIQ sourceid param set to value 001 due to wrong size in config section 3 chars max e.g. 1ab');
} else if (isHex(configParams.sourceid) == false) {
srcId = '002';
logInfo('NOVATIQ sourceid param set to value 002 due to wrong format in config section expecting hex value only');
} else {
srcId = configParams.sourceid;
}
Expand Down
21 changes: 10 additions & 11 deletions modules/novatiqIdSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ pbjs.setConfig({
auctionDelay: 50
}
});
```
```

### Parameters for the Novatiq Module
| Param | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | Module identification: `"novatiq"` | `"novatiq"` |
| params | Required | Object | Configuration specifications for the Novatiq module. | |
| params.sourceid | Required | String | This is the Novatiq Partner Number obtained via Novatiq registration. | `1a3` |
| params.sourceid | Required | String | The Novatiq Partner Number obtained via Novatiq | `1a3` |
| params.useSharedId | Optional | Boolean | Use the sharedID module if it's activated. | `true` |
| params.sharedIdName | Optional | String | Same as the SharedID "name" parameter <br /> Defaults to "_pubcid" | `"demo_pubcid"` |
| params.useCallbacks | Optional | Boolean | Use callbacks for custom integrations | `false` |
| params.urlParams | Optional | Object | Sync URl configuration for custom integrations | |
| params.urlParams.novatiqId | Optional | String | The name of the parameter used to indicate the novatiq ID uuid | `snowflake` |
| params.urlParams.useStandardUuid | Optional | Boolean | Use a standard UUID format, or the Novatiq UUID format | `false` |
| params.urlParams.useSspId | Optional | Boolean | Send the sspid (sourceid) along with the sync request | `false` |
| params.urlParams.useSspHost | Optional | Boolean | Send the ssphost along with the sync request | `false` |

# Novatiq Hyper ID with Prebid SharedID support
You can make use of the Prebid.js SharedId module as follows.
Expand Down Expand Up @@ -86,13 +94,4 @@ pbjs.setConfig({
});
```

### Parameters for the Novatiq Module
| Param | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | Module identification: `"novatiq"` | `"novatiq"` |
| params | Required | Object | Configuration specifications for the Novatiq module. | |
| params.sourceid | Required | String | The Novatiq Partner Number obtained via Novatiq | `1a3` |
| params.useSharedId | Optional | Boolean | Use the sharedID module if it's activated. | `true` |
| params.sharedIdName | Optional | String | Same as the SharedID "name" parameter <br /> Defaults to "_pubcid" | `"demo_pubcid"` |

If you have any questions, please reach out to us at prebid@novatiq.com.
Loading