This repository has been archived by the owner on May 10, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from autotrack to react-ga to get analytics working with next.js
- Loading branch information
Showing
3 changed files
with
17 additions
and
51 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
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,28 +1,21 @@ | ||
import { ANALYTICS_TRACKING_ID } from '../config'; | ||
import { IS_BROWSER } from '../util/website'; | ||
|
||
let ReactGA; | ||
if (IS_BROWSER) { | ||
ReactGA = require('react-ga'); // eslint-disable-line global-require | ||
} | ||
|
||
export function configureAnalytics() { | ||
if (IS_BROWSER) { | ||
// eslint-disable-next-line | ||
window.ga = window.ga || function () {(ga.q = ga.q || []).push(arguments)};ga.l = +new Date; | ||
/* global ga: true */ | ||
ga('create', ANALYTICS_TRACKING_ID, 'auto'); | ||
ga('require', 'urlChangeTracker'); | ||
/* eslint-disable global-require */ | ||
require('autotrack/lib/plugins/clean-url-tracker'); | ||
ga('require', 'cleanUrlTracker'); | ||
require('autotrack/lib/plugins/outbound-form-tracker'); | ||
ga('require', 'outboundFormTracker'); | ||
require('autotrack/lib/plugins/outbound-link-tracker'); | ||
/* eslint-enable global-require */ | ||
ga('require', 'outboundLinkTracker'); | ||
ReactGA.initialize(ANALYTICS_TRACKING_ID); | ||
} | ||
} | ||
|
||
export function pageView() { | ||
if (IS_BROWSER) { | ||
const page = window.location.pathname; | ||
ga('set', 'page', page); | ||
ga('send', 'pageview'); | ||
ReactGA.set({ page }); | ||
ReactGA.pageview(page); | ||
} | ||
} |
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