-
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.
Floc Userid System: add new ID module (#6521)
- Loading branch information
Showing
6 changed files
with
180 additions
and
13 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
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,110 @@ | ||
/** | ||
* This module adds flocId to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/flocId | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import * as utils from '../src/utils.js' | ||
import {submodule} from '../src/hook.js' | ||
|
||
const MODULE_NAME = 'flocId'; | ||
|
||
/** | ||
* Add meta tag to support enabling of floc origin trial | ||
* @function | ||
* @param {string} token - configured token for origin-trial | ||
*/ | ||
function enableOriginTrial(token) { | ||
const tokenElement = document.createElement('meta'); | ||
tokenElement.httpEquiv = 'origin-trial'; | ||
tokenElement.content = token; | ||
document.head.appendChild(tokenElement); | ||
} | ||
|
||
/** | ||
* Get the interest cohort. | ||
* @param successCallback | ||
* @param errorCallback | ||
*/ | ||
function getFlocData(successCallback, errorCallback) { | ||
document.interestCohort() | ||
.then((data) => { | ||
successCallback(data); | ||
}).catch((error) => { | ||
errorCallback(error); | ||
}); | ||
} | ||
|
||
/** | ||
* Encode the id | ||
* @param value | ||
* @returns {string|*} | ||
*/ | ||
function encodeId(value) { | ||
const result = {}; | ||
if (value) { | ||
result.flocId = value; | ||
utils.logInfo('Decoded value ' + JSON.stringify(result)); | ||
return result; | ||
} | ||
return undefined; | ||
} | ||
|
||
/** @type {Submodule} */ | ||
export const flocIdSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: MODULE_NAME, | ||
|
||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @param {string} value | ||
* @returns {{flocId:{ id: string }} or undefined if value doesn't exists | ||
*/ | ||
decode(value) { | ||
return (value) ? encodeId(value) : undefined; | ||
}, | ||
/** | ||
* If chrome and cohort enabled performs action to obtain id and return a value in the callback's response argument | ||
* @function | ||
* @param {SubmoduleConfig} [config] | ||
* @returns {IdResponse|undefined} | ||
*/ | ||
getId(config) { | ||
// Block usage of storage of cohort ID | ||
const checkStorage = (config && config.storage); | ||
if (checkStorage) { | ||
utils.logError('User ID - flocId submodule storage should not defined'); | ||
return; | ||
} | ||
// Validate feature is enabled | ||
const isFlocEnabled = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime) && !!document.featurePolicy && !!document.featurePolicy.features() && document.featurePolicy.features().includes('interest-cohort'); | ||
|
||
if (isFlocEnabled) { | ||
const configParams = (config && config.params) || {}; | ||
if (configParams && (typeof configParams.token === 'string')) { | ||
// Insert meta-tag with token from configuration | ||
enableOriginTrial(configParams.token); | ||
} | ||
// Example expected output { "id": "14159", "version": "chrome.1.0" } | ||
let returnCallback = (cb) => { | ||
getFlocData((data) => { | ||
returnCallback = () => { return data; } | ||
utils.logInfo('Cohort id: ' + JSON.stringify(data)); | ||
cb(data); | ||
}, (err) => { | ||
utils.logInfo(err); | ||
cb(undefined); | ||
}); | ||
}; | ||
|
||
return {callback: returnCallback}; | ||
} | ||
} | ||
}; | ||
|
||
submodule('userId', flocIdSubmodule); |
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,34 @@ | ||
## FloC ID User ID Submodule | ||
|
||
### Building Prebid with Floc Id Support | ||
Your Prebid build must include the modules for both **userId** and **flocIdSystem** submodule. Follow the build instructions for Prebid as | ||
explained in the top level README.md file of the Prebid source tree. | ||
|
||
ex: $ gulp build --modules=userId,flocIdSystem | ||
|
||
### Prebid Params | ||
|
||
Individual params may be set for the FloC ID User ID Submodule. | ||
``` | ||
pbjs.setConfig({ | ||
userSync: { | ||
userIds: [{ | ||
name: 'flocId', | ||
params: { | ||
token: "Registered token or default sharedid.org token" | ||
} | ||
}] | ||
} | ||
}); | ||
``` | ||
|
||
### Parameter Descriptions for the `userSync` Configuration Section | ||
The below parameters apply only to the FloC ID User ID Module integration. | ||
|
||
| Params under usersync.userIds[]| Scope | Type | Description | Example | | ||
| --- | --- | --- | --- | --- | | ||
| name | Required | String | ID value for the Floc ID module - `"flocId"` | `"flocId"` | | ||
| params | Optional | Object | Details for flocId syncing. | | | ||
| params.token | Optional | Object | Publisher registered token.To get new token, register https://developer.chrome.com/origintrials/#/trials/active for Federated Learning of Cohorts. Default sharedid.org token: token: "A3dHTSoNUMjjERBLlrvJSelNnwWUCwVQhZ5tNQ+sll7y+LkPPVZXtB77u2y7CweRIxiYaGwGXNlW1/dFp8VMEgIAAAB+eyJvcmlnaW4iOiJodHRwczovL3NoYXJlZGlkLm9yZzo0NDMiLCJmZWF0dXJlIjoiSW50ZXJlc3RDb2hvcnRBUEkiLCJleHBpcnkiOjE2MjYyMjA3OTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"| token: "A3dHTSoNUMjjERBLlrvJSelNnwWUCwVQhZ5tNQ+sll7y+LkPPVZXtB77u2y7CweRIxiYaGwGXNlW1/dFp8VMEgIAAAB+eyJvcmlnaW4iOiJodHRwczovL3NoYXJlZGlkLm9yZzo0NDMiLCJmZWF0dXJlIjoiSW50ZXJlc3RDb2hvcnRBUEkiLCJleHBpcnkiOjE2MjYyMjA3OTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9" | ||
| | ||
| storage | Not Allowed | Object | Will ask browser for cohort everytime. Setting storage will fail id lookup || |
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