@financial-times/react-o-tracking
v1.3.5
Published
React o-tracking module
Downloads
7
Readme
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);