Skip to content

Conversation

barshathakuri
Copy link
Collaborator

@barshathakuri barshathakuri commented Apr 3, 2025

Summary

Add logic for accept and reject cookie.

Addresses

  • Issue(s): List related issues or tickets.

Changes

  • Add Accept cookie logic
  • Add Reject cookie logic

This PR Ensures:

  • No typos or grammatical errors
  • No conflict markers left in the code
  • No unwanted comments, temporary files, or auto-generated files
  • No inclusion of secret keys or sensitive data
  • No console.log statements meant for debugging
  • All CI checks have passed

Additional

  • TODO: We need to discuss what the type is for window.

Copy link

changeset-bot bot commented Apr 3, 2025

⚠️ No Changeset found

Latest commit: cd96980

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +79 to +99
const loadGoogleAnalytics = useCallback(() => {
const consent = JSON.parse(sessionStorage.getItem('cookie-consent') || '{}');

if (isAuthenticated || consent.analytics) {
const win = window as CustomWindow;

if (!win.gtag) {
const script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-X';
script.async = true;
document.head.appendChild(script);

win.dataLayer = win.dataLayer || [];
win.gtag = (...args) => win.dataLayer!.push(args);
}

win.gtag('js', new Date());
// TODO Add Google Analytics ID
win.gtag('config', 'UA-XXXXXXX-X', { anonymize_ip: true });
}
}, [isAuthenticated]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this, also this function is flawed.
Some of it are,

  1. The TAG should be the actual google analytics tag. i, e. the placeholder tag doesn't work.
  2. We should use GA4 tags.
  3. This loading is already handled by the plugin that installs google analytics

}, [isAuthenticated]);

const handleAccept = useCallback(() => {
const consent = { analytics: true };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just use a boolean here

Comment on lines +116 to +119
const gaScript = document.querySelector('script[src*="googletagmanager.com/gtag/js"]');
if (gaScript) {
gaScript.remove();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to remove the script all-together. we should just update the consent.

}

// TODO: Add Google Analytics ID
window['ga-disable-UA-XXXXXXX-X'] = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work?

@frozenhelium frozenhelium marked this pull request as draft April 28, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants