-
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.
Novatiq ID System: add snowflake userId submodule (#6350)
* Novatiq snowflake userId submodule Novatiq snowflake userId submodule initial release * change request updates added novatiq info /modules/userId/userId.md added novatiq info /modules/userId/eids.md added novatiq eids /modules/userId/eids.js added novatiq module in /modules/.submodules.json removed unnecessary value from getId response * Update novatiqIdSystem_spec.js removed unnecessary srcid value * Update novatiqIdSystem.md Novatiq ID System: updated novatiq snowflake ID description
- Loading branch information
novatiq
authored
Mar 12, 2021
1 parent
8e764f6
commit 7282096
Showing
7 changed files
with
216 additions
and
1 deletion.
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
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,88 @@ | ||
/** | ||
* This module adds novatiqId to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/novatiqIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import * as utils from '../src/utils.js'; | ||
import { ajax } from '../src/ajax.js'; | ||
import { submodule } from '../src/hook.js'; | ||
|
||
/** @type {Submodule} */ | ||
export const novatiqIdSubmodule = { | ||
|
||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: 'novatiq', | ||
|
||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @returns {novatiq: {snowflake: string}} | ||
*/ | ||
decode(novatiqId, config) { | ||
let responseObj = { | ||
novatiq: { | ||
snowflake: novatiqId | ||
} | ||
}; | ||
return responseObj; | ||
}, | ||
|
||
/** | ||
* performs action to obtain id and return a value in the callback's response argument | ||
* @function | ||
* @param {SubmoduleConfig} config | ||
* @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); | ||
utils.logInfo('NOVATIQ Sync request used sourceid param: ' + srcId); | ||
|
||
let partnerhost; | ||
partnerhost = window.location.hostname; | ||
utils.logInfo('NOVATIQ partner hostname: ' + partnerhost); | ||
|
||
const novatiqId = snowflakeId(); | ||
const url = 'https://spadsync.com/sync?sptoken=' + novatiqId + '&sspid=' + srcId + '&ssphost=' + partnerhost; | ||
ajax(url, undefined, undefined, { method: 'GET', withCredentials: false }); | ||
|
||
utils.logInfo('NOVATIQ snowflake: ' + novatiqId); | ||
return { 'id': novatiqId } | ||
}, | ||
|
||
getSrcId(configParams) { | ||
utils.logInfo('NOVATIQ Configured sourceid param: ' + configParams.sourceid); | ||
|
||
function isHex(str) { | ||
var a = parseInt(str, 16); | ||
return (a.toString(16) === str) | ||
} | ||
|
||
let srcId; | ||
if (typeof configParams.sourceid === 'undefined' || configParams.sourceid === null || configParams.sourceid === '') { | ||
srcId = '000'; | ||
utils.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'; | ||
utils.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'; | ||
utils.logInfo('NOVATIQ sourceid param set to value 002 due to wrong format in config section expecting hex value only'); | ||
} else { | ||
srcId = configParams.sourceid; | ||
} | ||
return srcId | ||
} | ||
}; | ||
submodule('userId', novatiqIdSubmodule); |
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,36 @@ | ||
# Novatiq Snowflake ID | ||
|
||
Novatiq proprietary dynamic snowflake ID is a unique, non sequential and single use identifier for marketing activation. Our in network solution matches verification requests to telco network IDs, safely and securely inside telecom infrastructure. Novatiq snowflake ID can be used for identity validation and as a secured 1st party data delivery mechanism. | ||
|
||
## Novatiq Snowflake ID Configuration | ||
|
||
Enable by adding the Novatiq submodule to your Prebid.js package with: | ||
|
||
``` | ||
gulp build --modules=novatiqIdSystem,userId | ||
``` | ||
|
||
Module activation and configuration: | ||
|
||
```javascript | ||
pbjs.setConfig({ | ||
userSync: { | ||
userIds: [{ | ||
name: 'novatiq', | ||
params: { | ||
sourceid '1a3', // change to the Partner Number you received from Novatiq | ||
} | ||
} | ||
}], | ||
auctionDelay: 50 // 50ms maximum auction delay, applies to all userId modules | ||
} | ||
}); | ||
``` | ||
|
||
| Param under userSync.userIds[] | 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` | | ||
|
||
If you have any questions, please reach out to us at [email protected]. |
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
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
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
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,70 @@ | ||
import { novatiqIdSubmodule } from 'modules/novatiqIdSystem.js'; | ||
import * as utils from 'src/utils.js'; | ||
import { server } from 'test/mocks/xhr.js'; | ||
|
||
describe('novatiqIdSystem', function () { | ||
describe('getSrcId', function() { | ||
it('getSrcId should set srcId value to 000 due to undefined parameter in config section', function() { | ||
const config = { params: { } }; | ||
const configParams = config.params || {}; | ||
const response = novatiqIdSubmodule.getSrcId(configParams); | ||
expect(response).to.eq('000'); | ||
}); | ||
|
||
it('getSrcId should set srcId value to 000 due to missing value in config section', function() { | ||
const config = { params: { sourceid: '' } }; | ||
const configParams = config.params || {}; | ||
const response = novatiqIdSubmodule.getSrcId(configParams); | ||
expect(response).to.eq('000'); | ||
}); | ||
|
||
it('getSrcId should set value to 000 due to null value in config section', function() { | ||
const config = { params: { sourceid: null } }; | ||
const configParams = config.params || {}; | ||
const response = novatiqIdSubmodule.getSrcId(configParams); | ||
expect(response).to.eq('000'); | ||
}); | ||
|
||
it('getSrcId should set value to 001 due to wrong length in config section max 3 chars', function() { | ||
const config = { params: { sourceid: '1234' } }; | ||
const configParams = config.params || {}; | ||
const response = novatiqIdSubmodule.getSrcId(configParams); | ||
expect(response).to.eq('001'); | ||
}); | ||
|
||
it('getSrcId should set value to 002 due to wrong format in config section', function() { | ||
const config = { params: { sourceid: '1xc' } }; | ||
const configParams = config.params || {}; | ||
const response = novatiqIdSubmodule.getSrcId(configParams); | ||
expect(response).to.eq('002'); | ||
}); | ||
}); | ||
|
||
describe('getId', function() { | ||
it('should log message if novatiqId has wrong format', function() { | ||
const config = { params: { sourceid: '123' } }; | ||
const response = novatiqIdSubmodule.getId(config); | ||
expect(response.id).to.have.length(40); | ||
}); | ||
|
||
it('should log message if novatiqId not provided', function() { | ||
const config = { params: { sourceid: '123' } }; | ||
const response = novatiqIdSubmodule.getId(config); | ||
expect(response.id).should.be.not.empty; | ||
}); | ||
}); | ||
|
||
describe('decode', function() { | ||
it('should log message if novatiqId has wrong format', function() { | ||
const novatiqId = '81b001ec-8914-488c-a96e-8c220d4ee08895ef'; | ||
const response = novatiqIdSubmodule.decode(novatiqId); | ||
expect(response.novatiq.snowflake).to.have.length(40); | ||
}); | ||
|
||
it('should log message if novatiqId has wrong format', function() { | ||
const novatiqId = '81b001ec-8914-488c-a96e-8c220d4ee08895ef'; | ||
const response = novatiqIdSubmodule.decode(novatiqId); | ||
expect(response.novatiq.snowflake).should.be.not.empty; | ||
}); | ||
}); | ||
}) |