Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
improvement: update google analytics
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <[email protected]>
  • Loading branch information
mcansh committed Aug 19, 2019
1 parent d5a9b9e commit 57d7f2e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactGA from 'react-ga';
export const initGA = () => {
ReactGA.initialize(String(process.env.ANALYTICS));
};
export const logPageView = (page: string) => {
export const logPageView = (page: string = window.location.pathname) => {
ReactGA.set({ page });
ReactGA.pageview(page);
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@types/gtag.js": "0.0.2",
"@types/jest": "24.0.17",
"@types/jest-in-case": "1.0.1",
"@types/node": "12.7.2",
"@types/nprogress": "0.2.0",
"@types/prettier": "1.18.2",
"@types/react": "16.9.2",
Expand Down
8 changes: 3 additions & 5 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ class MyApp extends App<Props> {
}

public componentDidMount() {
if (!window.GA_INITIALIZED) {
initGA();
window.GA_INITIALIZED = true;
}
initGA();
logPageView();
Router.events.on('routeChangeComplete', logPageView);
}

public render() {
Router.events.on('routeChangeComplete', (url: string) => logPageView(url));
const { Component, pageProps } = this.props;

return (
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,11 @@
resolved "https://registry.npmjs.org/@types/node/-/node-11.9.4.tgz#ceb0048a546db453f6248f2d1d95e937a6f00a14"
integrity sha512-Zl8dGvAcEmadgs1tmSPcvwzO1YRsz38bVJQvH1RvRqSR9/5n61Q1ktcDL0ht3FXWR+ZpVmXVwN1LuH4Ax23NsA==

"@types/[email protected]":
version "12.7.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.2.tgz#c4e63af5e8823ce9cc3f0b34f7b998c2171f0c44"
integrity sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
Expand Down

0 comments on commit 57d7f2e

Please sign in to comment.