diff --git a/public/scripts/analytics/index.js b/public/scripts/analytics/index.js index 1d77da147884f..d0b550c1c2134 100644 --- a/public/scripts/analytics/index.js +++ b/public/scripts/analytics/index.js @@ -1,4 +1,4 @@ -// Version 1.0.5 +// Version 1.0.6 const cacheTrackEvents = { interval: null, responses: [], @@ -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()) { @@ -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;