use-tracker

0.1.0 • Public • Published

use-tracker

Easily add google analytics tracking (https://github.com/react-ga/react-ga) to your React pages


Installation

npm install --save use-tracker

Initializing - done at the top level before any Routing is done

import { init } from ' use-tracker';
 
// Use your GA tracking ID
init('UA-12345', process.env.NODE_ENV || 'production');

Importing the hook

import useTracker from ' use-tracker'  

Usage

use-tracker is powered by React Google Analytics in the background. Simply use the hook and provide a pathname and/or search string, and thats it.

import React from 'react';
import useTracker from 'use-tracker';
 
function YourPageComponent() {
  useTracker({
    pathname: 'stuff',
    search: '?and=things'
  });
  return (
    ...
  )
}

It works perfectly with React Router

import React from 'react';
import useTracker from 'use-tracker';
 
function YourPageComponent({ location }) {
  useTracker({
    pathname: location.pathname
    search: location.search
  });
  return (
    ...
  )
}

Package Sidebar

Install

npm i use-tracker

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

4.25 kB

Total Files

4

Last publish

Collaborators

  • sicknarlo