Skip to content

Commit

Permalink
feat: add clarity tracking code
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang authored Jul 9, 2024
1 parent 2d8942f commit ed658f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ sed -i "s@{VITE_ODD_QUESTIONNAIRE}@$VITE_ODD_QUESTIONNAIRE@g" /app/build/assets/
sed -i "s@{VITE_JTOOL_USERS}@$VITE_JTOOL_USERS@g" /app/build/assets/*.js
sed -i "s@{VITE_ODD_MAP}@$VITE_ODD_MAP@g" /app/build/assets/*.js

sed -i "s@{VITE_CLARITY_APP_ID}@$VITE_CLARITY_APP_ID@g" /app/build/index.html

# Restart nginx to apply changes
service nginx restart

Expand Down
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script type="text/javascript">
var undefinedClarityAppId = "{" + "VITE_CLARITY_APP_ID" + "}"
var clarityAppId = "{VITE_CLARITY_APP_ID}"
if (clarityAppId !== "" && clarityAppId !== undefinedClarityAppId) {
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", clarityAppId);
}
</script>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
9 changes: 9 additions & 0 deletions src/components/Routes/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { ACCESS_TOKEN } from '../../constants'
import { useAppSelector, useAppDispatch } from '../../state'
import { login } from '../../state/me'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const window: any

const ME = gql`
query me {
me {
Expand Down Expand Up @@ -43,6 +46,12 @@ const PrivateRoute: React.FC = () => {
}
}, [me, data, dispatch])

useEffect(() => {
if (window.clarity && me?.id) {
window.clarity('identify', me?.id)
}
}, [me?.id])

if (!me || (!me && !authToken) || error || (authToken && !loading && data && !data.me)) {
if (allowRedirect === true) return <Navigate to="/" replace />

Expand Down

0 comments on commit ed658f8

Please sign in to comment.