Skip to content

Commit

Permalink
feat(src): ✨ Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Nudelsuppe42 committed Jan 3, 2024
1 parent 9a49af0 commit 06120d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/CookieBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { Button, CloseButton, Group, Paper, Text } from '@mantine/core';
import { hasCookie, setCookie } from 'cookies-next';
import { AnimatePresence, motion } from 'framer-motion';
import { useEffect, useState } from 'react';

import { hasCookie } from 'cookies-next';
import classes from '../styles/components/CookieBanner.module.css';

export default function CookieBanner() {
const [showing, setShowing] = useState(false);

useEffect(() => {
setShowing(!hasCookie('bte_cookie_consent'));
setShowing(!hasCookie('mtm_cookie_consent'));
}, []);

const handleAcceptAll = () => {
setCookie('bte_cookie_consent', 'all', { maxAge: 60 * 60 * 24 * 120 });
//@ts-ignore
window._paq = window._paq || [];
//@ts-ignore
window._paq.push(['rememberCookieConsentGiven']);
setShowing(false);
};
const handleAcceptEssential = () => {
setCookie('bte_cookie_consent', 'ess', { maxAge: 60 * 60 * 24 * 120 });
setShowing(false);
};

Expand Down
15 changes: 15 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SessionProvider } from 'next-auth/react';
import { appWithTranslation } from 'next-i18next';
import { DefaultSeo } from 'next-seo';
import type { AppProps } from 'next/app';
import { useEffect } from 'react';
import defaultSeo from '../../next-seo.config';
import CookieBanner from '../components/CookieBanner';
import { RouterTransition } from '../components/RouterTransition';
Expand All @@ -29,6 +30,20 @@ function MyApp({ Component, pageProps }: AppProps) {
defaultValue: '',
});

useEffect(() => {
//@ts-ignore
var _mtm = (window._mtm = window._mtm || []);
_mtm.push({ 'mtm.startTime': new Date().getTime(), event: 'mtm.Start' });
(function () {
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = 'https://analytics.buildtheearth.net/js/container_PcCg1Bla.js';
s.parentNode?.insertBefore(g, s);
})();
});

return (
<SessionProvider session={pageProps.session}>
<DefaultSeo {...defaultSeo} />
Expand Down

0 comments on commit 06120d1

Please sign in to comment.