fetch-track
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Fetch Track

Simple method to fire analytics events using window.fetch. Highly customizable, lightweight, no dependencies.

If window.fetch does not exist (e.g. old browser), this library does nothing.

Installation

NPM: npm install --save fetch-track

Yarn: yarn add fetch-track

Usage

import {track} from 'fetch-track';
 
track('Clicked Button', {
  color: 'blue'
})

Configuration

Fetch Options

These options customize how the actual fetch call is made.

track.config({
  url: 'https://example.com/api/track',
  method: 'POST',
  headers: {}
});

Data Options

These options append properties to every track call.

// These are all the possible config options, only pass what you need
track.config({
  defaultProperties: {
    userId: 1
  },
  includeUserAgent: true,
  includeUrl: true
});

Mocking Mode

The mock option does console.log instead of doing the actual fetch. Very useful for Dev and QA environments.

track.config({
  mock: true
});

Readme

Keywords

none

Package Sidebar

Install

npm i fetch-track

Weekly Downloads

6

Version

0.2.0

License

MIT

Unpacked Size

90.9 kB

Total Files

12

Last publish

Collaborators

  • jdorn