5.0.9 • Published 9 months ago

@ndla/tracker v5.0.9

Weekly downloads
68
License
GPL-3.0
Repository
github
Last release
9 months ago

ndla-tracker

NDLA's tracker for google tag manager

Installation

# Using yarn:
yarn add @ndla/tracker

# Using npm:
npm install @ndla/tracker --save

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:

import { createBrowserHistory } from 'history';
import { configureTracker } from '@ndla/tracker';

const browserHistory = createBrowserHistory();

configureTracker({
  listen: browserHistory.listen,
  gaTrackingId: 'someGoogleAnalyticsId',
  googleTagManagerId: 'someGoogleTagMangerId',
});

ReactDOM.render(
  ...,
  document.getElementById('app'),
);

Tracking can be used in two different ways. Either with a default React component called HelmetWithTracker:

import { HelmetWithTracker } from "@ndla/tracker";

const SomeTrackableComponent = ({ title }) => {
  return (
    <div>
      <HelmetWithTracker title={title} />
      <p>A paragraph (hopefully)</p>
    </div>
  );
};

export default SomeTrackableComponent;

or you can customize when the tracking should be done and add dimensions:

import { useTracker } from "@ndla/tracker";
const TestComponent = () => {
  const { trackPageView } = useTracker();

  useEffect(() => {
    if (!article || !condB) return;
    // We recommend creating a custom function for converting to matomo dimensions
    const dims = getAllDimensions({ article });
    trackPageView({ dimensions: dims, title: "Test title" });
  }, [condA, condB]);

  return <div>Test</div>;
};

export default TestComponent;
5.0.9

9 months ago

5.0.8

9 months ago

5.0.7

12 months ago

5.0.6

1 year ago

5.0.5

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.4

2 years ago

4.0.3

2 years ago

3.0.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.1.0

2 years ago

2.0.5

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

1.0.0

3 years ago

2.0.0

3 years ago

0.6.1

3 years ago

0.5.2

3 years ago

0.6.1-alpha.20

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.0

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.1-alpha.40

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

7 years ago

0.3.0

7 years ago