1.3.5 • Published 5 years ago

@financial-times/react-o-tracking v1.3.5

Weekly downloads
56
License
ISC
Repository
github
Last release
5 years ago

react-o-tracking

React o-tracking module

Installation

With npm:

npm install @financial-times/react-o-tracking --save

Note that React is required for the <withAnalytics> component.

Usage

With npm

Initializing o-tracking and Tracking Pageviews:

import ReactOTracking from '@financial-times/react-o-tracking';
export const initOtracking = (userName, title) => ReactOTracking.initialize({
  server: serverEndpoint,
  options: {
    context: { product: 'cct', app: 'cct' },
    user: {
      user: userName,
      userSession: cookie.load('cmsUserSession'),
      subscriptions: {
        is_staff: true
      }
    },
    content: {
      asset_type: 'cct',
      section: 'Brand.CCT',
      title
    }
  }
});
initOtracking(user, title);

Sending custom events

export const sendOtrackingEvent = (category, action = 'click') => {
  const [, uuid] = uuidRegex.exec(window.location.href) || []
  const title = EditorStore.articleHistoryLatest[0].title
  ReactOTracking.sendEvent({ content: { uuid , title }, category, action })
}

sendOtrackingEvent('linkClicked')

Using HOC

class myComponent extends React.Component {
    render(){}
}
export default withAnalytics(myComponent);
1.3.5

5 years ago

1.0.1

6 years ago