Created
June 19, 2017 18:10
-
-
Save btnwtn/c9ac7c017f0fa7f1d8edb9547d1acdad to your computer and use it in GitHub Desktop.
GTM Tracking HOC
This file contains 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
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