Skip to content

Prince/add cookie status #2833

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion public/scripts/packages/marketing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deriv-com/marketing-utils",
"version": "1.0.11",
"version": "1.0.12",
"type": "module",
"repository": {
"type": "git",
Expand Down
58 changes: 58 additions & 0 deletions public/scripts/packages/marketing/src/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,63 @@
return stringifiedCookies;
};

const testCookieFunctionality = () => {
try {
// Test basic cookie functionality
document.cookie = "deriv_test_cookie=1; SameSite=None; Secure";
const test_result = document.cookie.includes("deriv_test_cookie=");

// Gather browser and cookie configuration info
const cookieInfo = {
status: test_result ? "enabled" : "disabled",
browser: {
userAgent: navigator.userAgent,
platform: navigator.platform,
vendor: navigator.vendor,
},
cookieConfig: {
sameSite: "None",
secure: true,
domain: getDomain(),
},
cookieSettings: {
thirdPartyCookies: test_result ? "supported" : "blocked",
cookieEnabled: navigator.cookieEnabled,
doNotTrack: navigator.doNotTrack || window.doNotTrack,
},
storage: {
localStorage: (() => {
try {
localStorage.setItem("test", "test");
localStorage.removeItem("test");
return "supported";
} catch (e) {
return "blocked";
}
})(),
sessionStorage: (() => {
try {
sessionStorage.setItem("test", "test");
sessionStorage.removeItem("test");
return "supported";
} catch (e) {
return "blocked";
}
})(),
}
};

if (!test_result) {
console.warn("⚠️ Cookies not stored - possibly ITP or blocked.");
}

return JSON.stringify(cookieInfo);
} catch (e) {
console.warn("❌ Cookie setting failed:", e);
return `error: ${e.message || e.toString()}`;
}
};

const waitForTrackEvent = (retries = 150, interval = 1000) => {
const getTrackEventFn = () => {
return window.Analytics?.trackEvent instanceof Function
Expand All @@ -354,6 +411,7 @@
console.warn("Marketing cookies has been handled");
trackEvent("debug_marketing_cookies", {
marketing_cookies: getStringifiedCookies(),
cookie_status: testCookieFunctionality(),
});
}, 1000);
} else if (retries > 0) {
Expand Down
Loading