Skip to content
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

Check for consent for hotjar #597

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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
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
Loading