Skip to content

Instantly share code, notes, and snippets.

@MaksimAbramchuk
Created December 22, 2017 09:26
Show Gist options
  • Save MaksimAbramchuk/fabb899a5029ddbf54a3a857c71e3d3e to your computer and use it in GitHub Desktop.
Save MaksimAbramchuk/fabb899a5029ddbf54a3a857c71e3d3e to your computer and use it in GitHub Desktop.
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