Skip to content

Commit

Permalink
Merge pull request #38 from SKOCHERI/DE-5945
Browse files Browse the repository at this point in the history
Set same shared id as eid
  • Loading branch information
SKOCHERI authored Mar 17, 2022
2 parents f071f43 + 415a5bf commit 171eac3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pubcid.js/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ <h1>Pubcid Collector Script Demo</h1>
const pubcid = googletag.encryptedSignalProviders.find(el => el.id === 'pubcid.org');
pubcid.collectorFunction();
</script>
Cookie pubcid.org stored
Local Storage pubcid.org stored
</body>
</html>
2 changes: 1 addition & 1 deletion pubcid.js/docs/pubcid.min.js

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

2 changes: 1 addition & 1 deletion pubcid.js/docs/pubcid.min.js.map

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

39 changes: 13 additions & 26 deletions pubcid.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,21 @@ const SOURCE = 'pubcid.org';

window.googletag = window.googletag || {cmd: []};
window.googletag.encryptedSignalProviders = window.googletag.encryptedSignalProviders || [];
window.pbjs = window.pbjs || [];

function collector() {
let value = getCookie();
if(value){
return;
}
value = generateUUID();
document.cookie = SOURCE + '=' + value;
}

/**
* Returns the cookie
* @returns {string}
*/
function getCookie() {
let name = SOURCE + "=";
let ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
return new Promise((resolve, reject) => {
const pubCommonUids = pbjs.getUserIdsAsEids().filter(function (eids) {
return eids && eids.source == SOURCE;
});
let pubcidValue = pubCommonUids ? pubCommonUids[0].uids[0].id : generateUUID();
window.localStorage.setItem(SOURCE, pubcidValue);
if (pubcidValue) {
resolve(pubcidValue);
} else {
reject("Setting local storage failed");
}
}
return "";
});
}

/**
Expand Down Expand Up @@ -56,7 +44,6 @@ function getRandomData() {
}

googletag.encryptedSignalProviders.push({
id: 'pubcid.org',
id: SOURCE,
collectorFunction: collector
});

0 comments on commit 171eac3

Please sign in to comment.