Merge pull request #54 from artslidd/develop

Grant all RUM tracking
This commit is contained in:
Arthur Belleville 2025-12-03 21:03:54 +01:00 committed by GitHub
commit 4064ce3e4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,10 @@
import { datadogRum } from "@datadog/browser-rum";
import { reactPlugin } from "@datadog/browser-rum-react";
import { getCookieConsent } from "../hooks/useCookieConsent";
// import { getCookieConsent } from "../hooks/useCookieConsent";
// Check if user has consented to analytics cookies before initializing
const consent = getCookieConsent();
const hasAnalyticsConsent = consent?.analytics ?? false;
// const consent = getCookieConsent();
// const hasAnalyticsConsent = consent?.analytics ?? false;
datadogRum.init({
applicationId: "8e268e1a-1be0-44c6-b12a-978530d497c7",
@ -22,32 +22,36 @@ datadogRum.init({
trackViewsManually: true,
trackUserInteractions: true,
trackResources: true,
trackingConsent: hasAnalyticsConsent ? "granted" : "not-granted",
// TODO: Uncomment when we have enough data
// trackingConsent: hasAnalyticsConsent ? "granted" : "not-granted",
trackingConsent: "granted",
startSessionReplayRecordingManually: false,
});
// Listen for storage changes to update tracking consent when cookie preferences change
window.addEventListener("storage", (event) => {
if (event.key === "xtablo-cookie-consent") {
const newConsent = getCookieConsent();
const newHasAnalyticsConsent = newConsent?.analytics ?? false;
// TODO: Uncomment when we have enough data
datadogRum.setTrackingConsent(newHasAnalyticsConsent ? "granted" : "not-granted");
}
});
// Listen for storage changes to update tracking consent when cookie preferences change
// window.addEventListener("storage", (event) => {
// if (event.key === "xtablo-cookie-consent") {
// const newConsent = getCookieConsent();
// const newHasAnalyticsConsent = newConsent?.analytics ?? false;
// datadogRum.setTrackingConsent(newHasAnalyticsConsent ? "granted" : "not-granted");
// }
// });
// Also listen for changes within the same tab (storage event doesn't fire for same-origin changes)
const originalSetItem = localStorage.setItem;
localStorage.setItem = function setItem(key, value) {
const result = originalSetItem.apply(this, [key, value]);
if (key === "xtablo-cookie-consent") {
const newConsent = getCookieConsent();
const newHasAnalyticsConsent = newConsent?.analytics ?? false;
// const originalSetItem = localStorage.setItem;
// localStorage.setItem = function setItem(key, value) {
// const result = originalSetItem.apply(this, [key, value]);
// if (key === "xtablo-cookie-consent") {
// const newConsent = getCookieConsent();
// const newHasAnalyticsConsent = newConsent?.analytics ?? false;
datadogRum.setTrackingConsent(newHasAnalyticsConsent ? "granted" : "not-granted");
}
// datadogRum.setTrackingConsent(newHasAnalyticsConsent ? "granted" : "not-granted");
// }
return result;
};
// return result;
// };
export default datadogRum;