Skip to content

Commit

Permalink
Check for consent for hotjar
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorreem committed Sep 20, 2023
1 parent 243d62b commit 04e51ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions guards/authGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Cookies from 'js-cookie';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import { hotjar } from 'react-hotjar';
Expand Down Expand Up @@ -128,8 +129,8 @@ export function AuthGuard({ children }: { children: JSX.Element }) {

// If the User state has already been populated and ID from the backend has been given set verified as true
if (user.id) {
if (process.env.NEXT_PUBLIC_ENV !== 'local') {
// TODO check consent of cookies before sending
// Check users analytics consent before sending user data
if (process.env.NEXT_PUBLIC_ENV !== 'local' && Cookies.get('analyticsConsent') === 'true') {
hotjar.identify('USER_ID', { userProperty: user.id });
}
setVerified(true);
Expand Down
8 changes: 8 additions & 0 deletions guards/publicPageDataWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Cookies from 'js-cookie';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import { hotjar } from 'react-hotjar';
import { api, useGetUserMutation } from '../app/api';
import { clearCoursesSlice } from '../app/coursesSlice';
import { clearPartnerAccessesSlice } from '../app/partnerAccessSlice';
Expand Down Expand Up @@ -91,6 +93,12 @@ export function PublicPageDataWrapper({ children }: { children: JSX.Element }) {
// User firebase token exists (i.e. user is logged in) but user data hasn't been loaded
callGetUser();
}
if (user.id && process.env.NEXT_PUBLIC_ENV !== 'local') {
// Checking for analytics consent before sending userIdentifiers to hotjar
if (Cookies.get('analyticsConsent') === 'true') {
hotjar.identify('USER_ID', { userProperty: user.id });
}
}
}, [getUser, router, user]);

return <>{children}</>;
Expand Down

0 comments on commit 04e51ca

Please sign in to comment.