1.0.0 • Published 3 years ago

@homeworksenergy/tracker v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

tracker

Usage - Tracker

import React, { useEffect } from 'react';
import { tracker } from 'ecomm-lib';
// Recommended: For "tree-shakable" imports, you can access modules individually:
// import tracker from 'ecomm-lib/build/tracker';

export const App = () => {
  // Initialize the tracker on App/page load.
  useEffect(() => {
    tracker.blacklisted = !isClient() || isBot();
    tracker.sendToCustomService = yourCustomAPICallHere;
    tracker.start();

    // Cleanup when the App unmounts... Not typically necessary, but good practice!
    return () => tracker.stop();
  }, []);

  const onClickButton = event => {
    tracker.track('Clicked button', { customProp: 'Whatever data you want to send!' });
  };

  return (
    <div>
      Hello world!
      <button onClick={onClickButton}>Track me!</button>
    </div>
  );
};