ndla-tracker
NDLA's tracker for google tag manager.
Installation
# Using npm: $ npm install ndla-tracker --save # Using yarn: $ yarn add ndla-tracker
Usage
To use the tracker you need to configure the tracker with correct google analytics id, google tag manager id and a listener for when the history changes:
;; const browserHistory = ; ; ReactDOM;
Tracking can be used in two different ways. Either with a default React component called HelmetWithTracker
:
; const SomeTrackableComponent = { return <div> <HelmetWithTracker title=title /> <p>A </p> </div> ;}; ;
or you can customize when the tracking should be done and add dimensions:
; Component static { return currentPropstitle; } static { const condition = currentProps; if condition ; } /* Add this function if you want to add custom dimensions to google tag manager or google analytics. */ static { return ga: dimensionGAOne: 'Some dimension in ga' gtm: dimensionGTMOne: 'Some dimension in gtm' ; } { const title = thisprops; return <div> <Helmet> <title>``</title> </Helmet> <p>A </p> </div> ; } SomeTrackableComponent;
PropTypes
PropTypes for HelmetWithTracker
Props | Type | Required | Description |
---|---|---|---|
title | String | * | A title (meta) used for the tracker. |