@siteone/react-analytics

1.0.11 • Public • Published

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 props props.analytics.send and binds every action in props.analytics
  • withTrackOnRender: calls ON EVERY RENDER (debounced and prevented to call twice same event) action from props props.analytics.send and binds every action in props.analytics
  • withAnalytics: not calling any event, only binds every action in props.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

Readme

Keywords

none

Package Sidebar

Install

npm i @siteone/react-analytics

Weekly Downloads

32

Version

1.0.11

License

MIT

Unpacked Size

996 kB

Total Files

15

Last publish

Collaborators

  • supermartin
  • siteonecz
  • hlavo-siteone
  • viktorbezdek
  • jiri.cerhan