Grant all RUM tracking
This commit is contained in:
parent
b253342ec9
commit
50a27fea98
1 changed files with 26 additions and 22 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue