Skip to content

Instantly share code, notes, and snippets.

@btnwtn
Created June 19, 2017 18:10
Show Gist options
  • Save btnwtn/c9ac7c017f0fa7f1d8edb9547d1acdad to your computer and use it in GitHub Desktop.
Save btnwtn/c9ac7c017f0fa7f1d8edb9547d1acdad to your computer and use it in GitHub Desktop.
GTM Tracking HOC
const withTracking = WrappedRoute => props => {
console.log(props);
if (window.dataLayer) {
window.dataLayer.push({
event: "pageview or something",
// https://developers.google.com/tag-manager/devguide
});
}
return <WrappedRoute {...props} />;
};
class App extends Component {
render() {
return (
<Router>
<Switch>
<Route path="/user/:id" component={withTracking(UserEditScreen)} />
<Route
path="/promo-codes"
component={withTracking(GenerateEntitlementCodesScreen)}
/>
<Route
path="/entitlement-code/:code"
component={withTracking(EntCodeSearchScreen)}
/>
<Route path="/" component={withTracking(UserSearchDashboard)} />
</Switch>
</Router>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment