2019-04-08 11:35:10 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import ReactGA from 'react-ga'
|
|
|
|
|
|
|
|
interface TrackerProps {
|
|
|
|
location: any
|
|
|
|
}
|
|
|
|
|
2019-04-08 12:07:09 +02:00
|
|
|
ReactGA.initialize('UA-60614729-11', {testMode: process.env.NODE_ENV === 'test'})
|
2019-04-08 11:35:10 +02:00
|
|
|
|
|
|
|
export default function withTracker(WrappedComponent: any, options: any = {}) {
|
|
|
|
const trackPage = (page: any) => {
|
|
|
|
options.isWeb3 = (window.web3 !== undefined)
|
|
|
|
ReactGA.set({
|
|
|
|
page,
|
|
|
|
...options
|
|
|
|
})
|
|
|
|
ReactGA.pageview(page)
|
|
|
|
}
|
|
|
|
|
|
|
|
const HOC = class extends Component<TrackerProps, {}> {
|
|
|
|
componentDidMount() {
|
|
|
|
const page = this.props.location.pathname + this.props.location.search
|
|
|
|
trackPage(page)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps: any) {
|
|
|
|
const currentPage = this.props.location.pathname;
|
|
|
|
const nextPage = nextProps.location.pathname;
|
|
|
|
|
|
|
|
if (currentPage !== nextPage) {
|
|
|
|
trackPage(nextProps.location.pathname + nextProps.location.search);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <WrappedComponent {...this.props} />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return HOC
|
|
|
|
}
|