1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-react-ga/utils/analytics.js
Vinay Puppal 7b62184c0b Add with-react-ga example (#2225)
* add with-react-ga example

* fix title in Readme
2017-06-09 23:44:26 +02:00

25 lines
601 B
JavaScript

import ReactGA from 'react-ga'
export const initGA = () => {
console.log('GA init')
ReactGA.initialize('UA-xxxxxxxxx-1')
}
export const logPageView = () => {
console.log(`Logging pageview for ${window.location.pathname}`)
ReactGA.set({ page: window.location.pathname })
ReactGA.pageview(window.location.pathname)
}
export const logEvent = (category = '', action = '') => {
if (category && action) {
ReactGA.event({ category, action })
}
}
export const logException = (description = '', fatal = false) => {
if (description) {
ReactGA.exception({ description, fatal })
}
}