Skip to content

Commit 81a9d43

Browse files
authored
Merge pull request #19 from mikaalnaik/google-analytics
google analytics
2 parents 3bbd8aa + 97796b4 commit 81a9d43

File tree

9 files changed

+112
-11
lines changed

9 files changed

+112
-11
lines changed

apps/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"devDependencies": {
3131
"@testing-library/jest-dom": "^5.14.1",
3232
"@testing-library/react": "^12.1.1",
33+
"@types/gtag.js": "^0.0.10",
3334
"@types/node": "^14.14.24",
3435
"@types/node-fetch": "^2.5.8",
3536
"@types/react": "^17.0.1",

apps/frontend/src/components/beach-card/beach-info-section/index.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface Props {
1616
const BeachInfoSection = ({ beach }: Props) => {
1717
const { collectionDate, beachId } = beach;
1818
const beachDisplayName = beachPositions(beachId).displayName;
19+
const sourceName = beach.beachId === 12 ? 'Swim Drink Fish' : 'City of Toronto';
20+
const prediction = undefined;
1921

2022
return (
2123
<div className={styles['beachcard-content']}>
@@ -25,9 +27,31 @@ const BeachInfoSection = ({ beach }: Props) => {
2527
{beachDisplayName}
2628
</div>
2729
</section>
28-
<EcoliStatusLabel beach={beach} />
29-
<div className={styles['collection-date']}>
30-
{dayjs(collectionDate).fromNow()}
30+
<div className={styles.readings}>
31+
<section className={styles['stat-row']}>
32+
<EcoliStatusLabel eColi={beach.eColi} />
33+
<div>
34+
<div className={styles.source}>
35+
{sourceName}
36+
</div>
37+
<div className={styles['collection-date']}>
38+
{dayjs(collectionDate).fromNow()}
39+
</div>
40+
</div>
41+
</section>
42+
{prediction && (
43+
<section className={styles['stat-row']}>
44+
<EcoliStatusLabel eColi={prediction} />
45+
<div>
46+
<div className={styles.source}>
47+
Our Prediction
48+
</div>
49+
<div className={styles['collection-date']}>
50+
for <b>today</b>
51+
</div>
52+
</div>
53+
</section>
54+
)}
3155
</div>
3256
</div>
3357
);

apps/frontend/src/components/beach-card/beach-info-section/style.module.scss

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@
3333
}
3434

3535
.collection-date {
36-
font-size: 0.65rem;
36+
font-size: 0.5rem;
3737
text-align: right;
3838
}
39+
40+
.source {
41+
text-align: right;
42+
font-size: 0.5rem;
43+
}
44+
45+
.stat-row {
46+
align-items: center;
47+
justify-content: flex-end;
48+
49+
&:last-of-type {
50+
margin-left: 10px;
51+
}
52+
}
53+
54+
.readings {
55+
display: flex;
56+
justify-content: end;
57+
}

apps/frontend/src/components/beach-card/ecoli-status-label/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import { Beach } from 'src/types/beaches';
22
import styles from './style.module.scss';
33

44
interface Props {
5-
beach: Beach;
5+
eColi: Beach['eColi'] | undefined
66
}
77

8-
const EcoliStatusLabel = ({ beach }: Props) => {
9-
const { eColi } = beach;
8+
const EcoliStatusLabel = ({ eColi }: Props) => {
109

11-
const label = eColi ? `${eColi} E. coli` : 'Not Tested';
10+
const label = eColi ? `${Math.round(eColi)} E. coli` : 'N/A';
1211

1312
return (
1413
<section className={styles.component}>

apps/frontend/src/components/layout/style.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
.home {
1919
position: relative;
20-
padding-top: 3rem;
20+
padding-top: 1rem;
2121
display: inline-block;
2222
width: 100%;
2323
}

apps/frontend/src/pages/_app.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
import { useRouter } from 'next/router';
2+
import { useEffect } from 'react';
13
import '../styles/app.scss';
24

35
// This default export is required in a new `pages/_app.js` file.
46
export default function MyApp({ Component, pageProps }) {
7+
const router = useRouter();
8+
9+
const handleRouteChange = url => {
10+
window.gtag('config', 'G-LC1XE1N6HK', {
11+
page_path: url,
12+
});
13+
};
14+
15+
useEffect(() => {
16+
router.events.on('routeChangeComplete', handleRouteChange);
17+
return () => {
18+
router.events.off('routeChangeComplete', handleRouteChange);
19+
};
20+
}, [router.events]);
21+
22+
523
return <Component {...pageProps} />;
624
}

apps/frontend/src/pages/_document.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
// pages/_document.js
22
import { Html, Head, Main, NextScript } from 'next/document';
3+
import Script from 'next/script';
34

45
export default function Document() {
56
return (
67
<Html>
7-
<Head />
8+
<Head>
9+
<link href="https://fonts.googleapis.com/css2?family=Jost:wght@200;400;500;700&display=swap" rel="stylesheet"></link>
10+
<Script
11+
strategy='afterInteractive'
12+
src="https://www.googletagmanager.com/gtag/js?id=G-LC1XE1N6HK"
13+
/>
14+
<Script
15+
strategy='afterInteractive'
16+
dangerouslySetInnerHTML={{
17+
__html: `
18+
window.dataLayer = window.dataLayer || [];
19+
function gtag(){dataLayer.push(arguments);}
20+
gtag('js', new Date());
21+
gtag('config', 'G-LC1XE1N6HK', { page_path: window.location.pathname });
22+
`,
23+
}}
24+
/>
25+
26+
</Head>
827
<body>
928
<Main />
1029
<link rel="preconnect" href="https://fonts.googleapis.com" />
1130
<link rel="preconnect" href="https://fonts.gstatic.com" />
12-
<link href="https://fonts.googleapis.com/css2?family=Jost:wght@200;400;500;700&display=swap" rel="stylesheet"></link>
1331
<NextScript />
1432
</body>
1533
</Html>

apps/frontend/src/utils/analytics.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
4+
export const pageview = url => {
5+
window.gtag('config', 'G-LC1XE1N6HK', {
6+
page_path: url,
7+
});
8+
};
9+
10+
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
11+
export const event = ({ action, category, label, value }) => {
12+
window.gtag('event', action, {
13+
event_category: category,
14+
event_label: label,
15+
value: value,
16+
});
17+
};

apps/frontend/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,11 @@
724724
dependencies:
725725
"@types/node" "*"
726726

727+
"@types/gtag.js@^0.0.10":
728+
version "0.0.10"
729+
resolved "https://registry.yarnpkg.com/@types/gtag.js/-/gtag.js-0.0.10.tgz#ac90d9b79c00daac447725a4b78ec1c398796760"
730+
integrity sha512-98Hy7woUb3jMAMXkZQwfIOYNyfxmI0+U4m0PpCGdnd/FHk0tDpQFCqgXdNkdEoXsKkcGya/2Gew1cAJjKJspVw==
731+
727732
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
728733
version "2.0.4"
729734
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"

0 commit comments

Comments
 (0)