Skip to content

Commit

Permalink
chore: add email hash on events
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-deriv committed Oct 11, 2024
1 parent 4096411 commit 251c8b9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion public/scripts/analytics/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Version 1.0.5
// Version 1.0.6
const cacheTrackEvents = {
interval: null,
responses: [],
Expand All @@ -24,6 +24,20 @@ const cacheTrackEvents = {

return combined.substring(0, desiredLength);
},
getCookie: (name) => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) {
const cookieValue = decodeURIComponent(parts.pop().split(";").shift());

try {
return JSON.parse(cookieValue);
} catch (e) {
return cookieValue;
}
}
return null;
},
trackPageUnload: () => {
window.addEventListener("beforeunload", (event) => {
if (!cacheTrackEvents.isPageViewSent()) {
Expand Down Expand Up @@ -107,6 +121,16 @@ const cacheTrackEvents = {
)}; path=/; Domain=.deriv.com`;
},
processEvent: (event) => {
const clientInfo = getCookies("client_information");

if (clientInfo) {
const { email = null } = clientInfo;

if (email) {
event.properties.email_hash = cacheTrackEvents.hash(email);
}
}

if (event?.properties?.email) {
const email = event.properties.email;
delete event.properties.email;
Expand Down

0 comments on commit 251c8b9

Please sign in to comment.