Created
December 22, 2017 09:26
-
-
Save MaksimAbramchuk/fabb899a5029ddbf54a3a857c71e3d3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react'; | |
import GoogleAnalytics from 'react-ga'; | |
const { NODE_ENV } = process.env; | |
GoogleAnalytics.initialize('UA-47365686-9'); | |
const withTracker = (WrappedComponent) => { | |
const trackPage = (page) => { | |
GoogleAnalytics.set({ page }); | |
GoogleAnalytics.pageview(page); | |
}; | |
const HOC = (props) => { | |
const page = props.location.pathname; | |
if (NODE_ENV === 'production') { | |
trackPage(page); | |
} | |
window.Intercom("update"); | |
return ( | |
<WrappedComponent {...props} /> | |
); | |
}; | |
return HOC; | |
}; | |
export default withTracker; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment