@siteone/react-analytics
v1.0.11
Published
Set of tools to provide better analytics events
Downloads
154
Keywords
Readme
React analytics
Set of tools to provide better analytics events.
Sends actions to redux on desired events.
ApolloServerRouter
Export consists of few HoC:
withTrackOnPageView
: calls ONE TIME action from propsprops.analytics.send
and binds every action inprops.analytics
withTrackOnRender
: calls ON EVERY RENDER (debounced and prevented to call twice same event) action from propsprops.analytics.send
and binds every action inprops.analytics
withAnalytics
: not calling any event, only binds every action inprops.analytics
Example:
import React from 'react'
import { withProps } from 'recompose'
import { withTrackOnPageView } from '@siteone/react-analytics'
const Component = ({ analytics }) => (
<div>
Hello World
<button onClick={analytics.onClick}>Measure click!</button>
</div>
)
const withAnalyticsData = withProps((props) => ({
analytics: {
// OPTIONAL: if you want do to fire event after data is loaded
isReady: !props.countryData.loading,
// "send" will be called automatically
send: { type: 'TRACK_PAGEVIEW' }, // action may be action object to be dispatched to redux
// OPTIONAL: you can define any variables (like "click") and their will be bounded to redux
onClick: (...args) => { type: 'CLICK', ...args }, // it also accepts function, that will return action object
}
}))
export default compose(withAnalyticsData, withTrackOnPageView)(Component)
Version: 1.3.6