-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2a0ca1
commit 81fef28
Showing
21 changed files
with
429 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
morpheus-client/components/CookiesConsent/CookiesConsent.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
@use "styles/colors"; | ||
@use "styles/media"; | ||
@use "styles/variables"; | ||
|
||
|
||
.cookiesContainer { | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
width: 100vw; | ||
min-height: 50px; | ||
height: auto; | ||
z-index: 999; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background-color: rgba(0, 0, 0, 0.9); | ||
padding: 20px; | ||
|
||
@include media.mobile { | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
} | ||
|
||
.textContainer { | ||
width: 70%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
|
||
a { | ||
display: block; | ||
text-decoration: underline; | ||
} | ||
|
||
@include media.mobile { | ||
width: 100%; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} | ||
} | ||
|
||
.buttonsSection { | ||
width: auto; | ||
margin-left: 24px; | ||
display: flex; | ||
justify-content: space-between; | ||
min-width: 400px; | ||
padding-right: 24px; | ||
|
||
@include media.mobile { | ||
width: 100%; | ||
flex-direction: column; | ||
margin: 24px 0 0 0; | ||
} | ||
|
||
button { | ||
:first-child { | ||
margin-right: 24px !important; | ||
} | ||
|
||
@include media.mobile { | ||
width: 100%; | ||
margin: 8px !important; | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
morpheus-client/components/CookiesConsent/CookiesConsent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useAnalytics } from "@/context/GoogleAnalyticsContext"; | ||
import { deleteAllCookies, CookiesStatus } from "@/utils/cookies"; | ||
import { useLocalStorage } from "@/hooks/useLocalStorage"; | ||
import styles from "./CookiesConsent.module.scss"; | ||
|
||
|
||
|
||
const CookiesConsent = () => { | ||
const [finalStatus, setFinalStatus] = useState(""); | ||
const { cookiesStatus, setCookiesStatus } = useAnalytics(); | ||
|
||
const [localCookies, setLocalCookies] = useLocalStorage<string | null>("cp:cookies", null); | ||
|
||
|
||
useEffect(() => { | ||
const newStatus = localCookies || cookiesStatus || ""; | ||
setFinalStatus(newStatus); | ||
if (newStatus !== "") { | ||
if (localCookies && localCookies !== "") setCookiesStatus(localCookies); | ||
} | ||
}, [localCookies, setCookiesStatus, cookiesStatus]); | ||
|
||
const handleActionCookies = (event: any, status: string) => { | ||
event.preventDefault(); | ||
|
||
if (status === CookiesStatus.Declined) { | ||
deleteAllCookies(); | ||
} | ||
|
||
setCookiesStatus(status); | ||
setLocalCookies(status); | ||
}; | ||
|
||
return finalStatus === "" ? ( | ||
<div className={styles.cookiesContainer}> | ||
<div className={styles.textContainer}> | ||
<p className="body-1 secondary"> | ||
This website uses cookies to ensure you get the best experience on our | ||
website. | ||
<a className="underline text-primary" target="_blank" href=""> | ||
Privacy Policy | ||
</a> | ||
</p> | ||
</div> | ||
|
||
<div className={styles.buttonsSection}> | ||
<button | ||
className="buttonSubmit" | ||
onClick={(event) => handleActionCookies(event, CookiesStatus.Declined)} | ||
> | ||
Decline | ||
</button> | ||
|
||
<button | ||
className="buttonSubmit" | ||
onClick={(event) => handleActionCookies(event, CookiesStatus.Accepted)} | ||
> | ||
Accept | ||
</button> | ||
</div> | ||
</div> | ||
) : null; | ||
}; | ||
|
||
export default CookiesConsent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createContext, ReactNode, useContext, useEffect, useState } from "react"; | ||
import { useRouter } from "next/router"; | ||
import { analytics } from "../lib/firebaseClient"; | ||
import { logEvent } from "firebase/analytics"; | ||
import { CookiesStatus } from "@/utils/cookies"; | ||
|
||
export interface IAnalyticsContext { | ||
analytics: any; | ||
cookiesStatus: string; | ||
setCookiesStatus: (accept: string) => void; | ||
sendAnalyticsRecord: (type: string, message: any) => void; | ||
} | ||
|
||
const defaultState = { | ||
analytics: undefined, | ||
cookiesStatus: "", | ||
setCookiesStatus: () => {}, | ||
sendAnalyticsRecord: () => {}, | ||
}; | ||
|
||
const AnalyticsContext = createContext<IAnalyticsContext>(defaultState); | ||
|
||
const FirebaseTrackingProvider = (props: { children: ReactNode }) => { | ||
const router = useRouter(); | ||
const [cookiesStatus, setCookiesStatus] = useState(""); | ||
|
||
useEffect(() => { | ||
const handleRouteChange = (url: string) => { | ||
if (cookiesStatus === CookiesStatus.Accepted && analytics) { | ||
return; | ||
} | ||
|
||
logEvent(analytics, "page_view", { | ||
page_location: url, | ||
page_title: document?.title, | ||
}); | ||
}; | ||
|
||
router.events.on("routeChangeStart", handleRouteChange); | ||
|
||
return () => { | ||
router.events.off("routeChangeStart", handleRouteChange); | ||
}; | ||
}, [cookiesStatus, router.events]); | ||
|
||
const sendAnalyticsRecord = (type: string, parameters: object) => { | ||
if (cookiesStatus === CookiesStatus.Accepted && analytics) { | ||
logEvent(analytics, type, parameters); | ||
} | ||
}; | ||
|
||
return ( | ||
<AnalyticsContext.Provider | ||
value={{ | ||
analytics, | ||
cookiesStatus, | ||
setCookiesStatus, | ||
sendAnalyticsRecord, | ||
}} | ||
> | ||
{props.children} | ||
</AnalyticsContext.Provider> | ||
); | ||
}; | ||
|
||
const useAnalytics = () => { | ||
const context = useContext(AnalyticsContext); | ||
if (context === undefined) { | ||
throw new Error("useAnalytics must be used within a AnalyticsProvider"); | ||
} | ||
return context; | ||
}; | ||
|
||
export { FirebaseTrackingProvider, useAnalytics }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { useEffect } from "react"; | ||
|
||
import { CookiesStatus } from "@/utils/cookies"; | ||
import { useAnalytics } from "@/context/GoogleAnalyticsContext"; | ||
import MainContainer from "../layout/MainContainer/MainContainer"; | ||
import FAQ from "../components/FAQ/FAQ"; | ||
import { AppLink } from "@/components/AppLink/AppLink"; | ||
|
@@ -12,6 +16,18 @@ import { | |
import styles from "../styles/pages/About.module.scss"; | ||
|
||
const About = () => { | ||
const { cookiesStatus, sendAnalyticsRecord } = useAnalytics(); | ||
|
||
useEffect(() => { | ||
if (cookiesStatus === CookiesStatus.Accepted) { | ||
sendAnalyticsRecord("page_view", { | ||
page_location: window.location.href, | ||
page_title: document?.title, | ||
page_name: "About", | ||
}); | ||
} | ||
}, [cookiesStatus, sendAnalyticsRecord]); | ||
|
||
return ( | ||
<MainContainer showFooter={true} style={{ justifyContent: "center" }}> | ||
<div className={styles.aboutContainer}> | ||
|
@@ -57,13 +73,13 @@ const About = () => { | |
<p className="body-1 secondary"> | ||
We’re hoping to get some feedback from users like you! Do you find | ||
this useful? Are there features missing from our{" "} | ||
<a className="app-link body-1 main underline" href="#roadmap"> | ||
<a className="underline app-link body-1 main" href="#roadmap"> | ||
roadmap | ||
</a>{" "} | ||
that you would like to see? Run into any problems or bugs? We want | ||
to hear about it! Contact us via{" "} | ||
<a | ||
className="body-1 main underline" | ||
className="underline body-1 main" | ||
href="mailto:[email protected]" | ||
> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.