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

symitriDapRtdProvider : Hash user identity before using it #12129

Merged
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
132 changes: 132 additions & 0 deletions integrationExamples/gpt/symitridap_segments_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<html>
<head>
<script async src="../../build/dev/prebid.js"></script>
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<script>
var FAILSAFE_TIMEOUT = 3300;
var PREBID_TIMEOUT = 2000;

var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]],
}
},
// Replace this object to test a new Adapter!
bids: [
{
bidder: 'appnexus',
params: {
placementId: 13144370
}
},
{
bidder: 'sovrn',
params: {
tagid: 1
}
}
]

}];

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

</script>

<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function() {
pbjs.setConfig({
debug: true,
ortb2: {
user: {
data: [
// DAP segment taxonomy inserted here
]
},
site: {
ext: {
data: {
// DAP SAID will be inserted here
}
}
},
imp: {
ext: {
data: {
// DAP SAID will be inserted here
}
}
}
},
realTimeData: {
auctionDelay: 2000,
dataProviders: [
{
name: "symitriDap",
waitForIt: true,
params: {
apiHostname: "api.dap.symitri.net",
apiVersion: "x1",
domain: "prebid.org",
identityValue: "test@invalid.com",
identityType: "hid"
}
}
]
}
});
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest,
timeout: PREBID_TIMEOUT
});
});

function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}

setTimeout(function() {
sendAdserverRequest();
}, FAILSAFE_TIMEOUT);

</script>

<script>
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

<script>!function(a){var e="https://s.go-mpulse.net/boomerang/",t="addEventListener";if("False"=="True")a.BOOMR_config=a.BOOMR_config||{},a.BOOMR_config.PageParams=a.BOOMR_config.PageParams||{},a.BOOMR_config.PageParams.pci=!0,e="https://s2.go-mpulse.net/boomerang/";if(window.BOOMR_API_key="5G3ZS-8L7PG-U23WM-5CA4K-LQ3YP",function(){function n(e){a.BOOMR_onload=e&&e.timeStamp||(new Date).getTime()}if(!a.BOOMR||!a.BOOMR.version&&!a.BOOMR.snippetExecuted){a.BOOMR=a.BOOMR||{},a.BOOMR.snippetExecuted=!0;var i,_,o,r=document.createElement("iframe");if(a[t])a[t]("load",n,!1);else if(a.attachEvent)a.attachEvent("onload",n);r.src="javascript:void(0)",r.title="",r.role="presentation",(r.frameElement||r).style.cssText="width:0;height:0;border:0;display:none;",o=document.getElementsByTagName("script")[0],o.parentNode.insertBefore(r,o);try{_=r.contentWindow.document}catch(O){i=document.domain,r.src="javascript:var d=document.open();d.domain='"+i+"';void(0);",_=r.contentWindow.document}_.open()._l=function(){var a=this.createElement("script");if(i)this.domain=i;a.id="boomr-if-as",a.src=e+"5G3ZS-8L7PG-U23WM-5CA4K-LQ3YP",BOOMR_lstart=(new Date).getTime(),this.body.appendChild(a)},_.write("<bo"+'dy onload="document._l();">'),_.close()}}(),"".length>0)if(a&&"performance"in a&&a.performance&&"function"==typeof a.performance.setResourceTimingBufferSize)a.performance.setResourceTimingBufferSize();!function(){if(BOOMR=a.BOOMR||{},BOOMR.plugins=BOOMR.plugins||{},!BOOMR.plugins.AK){var e=""=="true"?1:0,t="",n="ghh4w4yxem66iyi6ijxa-f-a8f1ed317-clientnsv4-s.akamaihd.net",i="false"=="true"?2:1,_={"ak.v":"32","ak.cp":"540505","ak.ai":parseInt("351538",10),"ak.ol":"0","ak.cr":17,"ak.ipv":4,"ak.proto":"http/1.1","ak.rid":"322de403","ak.r":36326,"ak.a2":e,"ak.m":"dscx","ak.n":"essl","ak.bpcip":"49.207.203.0","ak.cport":5172,"ak.gh":"23.47.149.85","ak.quicv":"","ak.tlsv":"tls1.2","ak.0rtt":"","ak.csrc":"-","ak.acc":"bbr","ak.t":"1629373038","ak.ak":"hOBiQwZUYzCg5VSAfCLimQ==admFPBlxVf0VKeanKFKUThzq+or23aIaVFP5DBXpeOGEuvD5mQz0UZbvK242Y8cupS91bsNaM7uJT3/O00EszGTxlFhkv439YkTWfyegvqVlJhcrZ7jcRkIoyrmjoBqDZoF0WaG4rhwmNzkKEv6T1noRYwEWwRHOG8p7osPXWy5as6KkmhOYUiYk8S5hQj+HFzhYI5YUTx+8urmHdpVIDBkramcrT2V89mb0cH5L2bSGS2hahAA3Kkf+0Dul7r5hDFQaVTf17e4oKdM1G8cKVF5LGRxRl3v4Rn6tBJ+fjrJ7XYQWV30w1LPwcAmSfRX8iTCK4xzHwG1fwDFHb5tWVsxHeEkRgNN3/KhnrCjxKtaROjJeWypJf/rjn1HWHwy7uVVsP9f/HRN3drCCkEvJBmu6yi0jzFFCoeEkbUEoq+8=","ak.pv":"396","ak.dpoabenc":"","ak.tf":i};if(""!==t)_["ak.ruds"]=t;var o={i:!1,av:function(e){var t="http.initiator";if(e&&(!e[t]||"spa_hard"===e[t]))_["ak.feo"]=void 0!==a.aFeoApplied?1:0,BOOMR.addVar(_)},rv:function(){var a=["ak.bpcip","ak.cport","ak.cr","ak.csrc","ak.gh","ak.ipv","ak.m","ak.n","ak.ol","ak.proto","ak.quicv","ak.tlsv","ak.0rtt","ak.r","ak.acc","ak.t","ak.tf"];BOOMR.removeVar(a)}};BOOMR.plugins.AK={akVars:_,akDNSPreFetchDomain:n,init:function(){if(!o.i){var a=BOOMR.subscribe;a("before_beacon",o.av,null,null),a("onbeacon",o.rv,null,null),o.i=!0}return this},is_complete:function(){return!0}}}}()}(window);</script></head>

<body>
<h2>Prebid.js Test</h2>
<h5>Div-1</h5>
<div id='div-gpt-ad-1460505748561-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1460505748561-0'); });
</script>
</div>
<h5>Segments Sent to Bidding Adapter</h5>
<div id="user-segments"></div>
</body>
</html>
2 changes: 1 addition & 1 deletion libraries/creative-renderer-display/renderer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libraries/creative-renderer-native/renderer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 53 additions & 28 deletions modules/symitriDapRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,41 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
*/
function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
let entropyDict = JSON.parse(storage.getDataFromLocalStorage(DAP_CLIENT_ENTROPY));
let loadScriptPromise = new Promise((resolve, reject) => {
if (rtdConfig && rtdConfig.params && rtdConfig.params.dapEntropyTimeout && Number.isInteger(rtdConfig.params.dapEntropyTimeout)) {
setTimeout(reject, rtdConfig.params.dapEntropyTimeout, Error('DapEntropy script could not be loaded'));
}
if (entropyDict && entropyDict.expires_at > Math.round(Date.now() / 1000.0)) {
logMessage('Using cached entropy');
resolve();
} else {
if (typeof window.dapCalculateEntropy === 'function') {
window.dapCalculateEntropy(resolve, reject);

// Attempt to load entroy script if no entropy object exist and entropy config settings are present.
// Else
if (!entropyDict && rtdConfig && rtdConfig.params && dapUtils.isValidHttpsUrl(rtdConfig.params.dapEntropyUrl)) {
let loadScriptPromise = new Promise((resolve, reject) => {
if (rtdConfig && rtdConfig.params && rtdConfig.params.dapEntropyTimeout && Number.isInteger(rtdConfig.params.dapEntropyTimeout)) {
setTimeout(reject, rtdConfig.params.dapEntropyTimeout, Error('DapEntropy script could not be loaded'));
}
if (entropyDict && entropyDict.expires_at > Math.round(Date.now() / 1000.0)) {
logMessage('Using cached entropy');
resolve();
} else {
if (rtdConfig && rtdConfig.params && dapUtils.isValidHttpsUrl(rtdConfig.params.dapEntropyUrl)) {
loadExternalScript(rtdConfig.params.dapEntropyUrl, MODULE_CODE, () => { dapUtils.dapGetEntropy(resolve, reject) });
if (typeof window.dapCalculateEntropy === 'function') {
window.dapCalculateEntropy(resolve, reject);
} else {
reject(Error('Please check if dapEntropyUrl is specified and is valid under config.params'));
if (rtdConfig && rtdConfig.params && dapUtils.isValidHttpsUrl(rtdConfig.params.dapEntropyUrl)) {
loadExternalScript(rtdConfig.params.dapEntropyUrl, MODULE_CODE, () => { dapUtils.dapGetEntropy(resolve, reject) });
} else {
reject(Error('Please check if dapEntropyUrl is specified and is valid under config.params'));
}
}
}
}
});
loadScriptPromise
.catch((error) => {
logError('Entropy could not be calculated due to: ', error.message);
})
.finally(() => {
generateRealTimeData(bidConfig, onDone, rtdConfig, userConsent);
});

loadScriptPromise
.catch((error) => {
logError('Entropy could not be calculated due to: ', error.message);
})
.finally(() => {
generateRealTimeData(bidConfig, onDone, rtdConfig, userConsent);
});
} else {
logMessage('No dapEntropyUrl is specified.');
generateRealTimeData(bidConfig, onDone, rtdConfig, userConsent);
}
}

function generateRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
Expand Down Expand Up @@ -131,18 +140,17 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) {

/**
* Module init
* @param {Object} provider
* @param {Object} config
* @param {Object} userConsent
* @return {boolean}
*/
function init(provider, userConsent) {
function init(config, userConsent) {
if (dapUtils.checkConsent(userConsent) === false) {
return false;
}
return true;
}

/** @type {RtdSubmodule} */
const rtdSubmodule = {
name: SUBMODULE_NAME,
getBidRequestData: getRealTimeData,
Expand All @@ -159,7 +167,7 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
api_version: rtdConfig.params.apiVersion,
domain: rtdConfig.params.domain,
segtax: rtdConfig.params.segtax,
identity: {type: rtdConfig.params.identityType}
identity: {type: rtdConfig.params.identityType, value: rtdConfig.params.identityValue},
};
let refreshMembership = true;
let token = dapUtils.dapGetTokenFromLocalStorage();
Expand Down Expand Up @@ -526,6 +534,16 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
return [ config, false ];
},

addIdentifier: async function(identity, apiParams) {
if (window.crypto && window.crypto.subtle && typeof (identity.value) != typeof (undefined) && identity.value.trim() !== '') {
const hashBuffer = await window.crypto.subtle.digest('SHA-256', new TextEncoder().encode(identity.value));
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
apiParams.identity = hashHex.toUpperCase();
}
return apiParams
},

/**
* SYNOPSIS
*
Expand Down Expand Up @@ -594,9 +612,16 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
'type': identity.type,
};

if (typeof (identity.identity) != typeof (undefined)) {
apiParams.identity = identity.identity;
if (identity.type === 'hid') {
this.addIdentifier(identity, apiParams).then((apiParams) => {
this.callTokenize(config, identity, apiParams, onDone, onSuccess, onError);
});
} else {
this.callTokenize(config, identity, apiParams, onDone, onSuccess, onError);
}
},

callTokenize(config, identity, apiParams, onDone, onSuccess, onError) {
if (typeof (identity.attributes) != typeof (undefined)) {
apiParams.attributes = identity.attributes;
}
Expand All @@ -621,7 +646,7 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
return;
}

let customHeaders = {'Content-Type': 'application/json'};
let customHeaders = { 'Content-Type': 'application/json' };
let dapSSID = JSON.parse(storage.getDataFromLocalStorage(DAP_SS_ID));
if (dapSSID) {
customHeaders[headerPrefix + '-DAP-SS-ID'] = dapSSID;
Expand Down
Loading