1.0.11 • Published 4 years ago

@standardorg/analytics-fetch v1.0.11

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

Fetch plugin for analytics

Integration with the browser's fetch API for analytics

Installation

npm install analytics
npm install @standard-org/analytics-fetch

How to use

The @standard-org/analytics-fetch package works in the browser and server-side in Node.js. To use, install the package, include in your project and initialize the plugin with analytics.

Below is an example of how to use the browser plugin.

import Analytics from 'analytics'
import analyticsFetch from "@standardorg/analytics-fetch";

const analytics = Analytics({
  app: "bookclub",
  plugins: [
    analyticsFetch(
      (action) => `https://my-tracking-url.com/${action}`,
    ),
  ],
});

/* Track a page view */
analytics.page()

/* Track a custom event */
analytics.track('cartCheckout', {
  item: 'pink socks',
  price: 20
})

/* Identify a visitor */
analytics.identify('user-id-xyz', {
  firstName: 'bill',
  lastName: 'murray'
})

After initializing analytics with the analyticsFetch plugin, data will be sent to your own analytics endpoint whenever analytics.page, analytics.track, or analytics.identify are called.

Platforms Supported

The @standardorg/analytics-fetch package works in the browser and server-side in Node.js

Browser usage

The Analytics Fetch client side browser plugin works with these analytic api methods:

Browser API

import Analytics from 'analytics'
import analyticsFetch from '@standardorg/analytics-fetch'

const analytics = Analytics({
  app: 'awesome-app',
  plugins: [
    analyticsFetch(
      (action) => `https://my-tracking-url.com/${action}`,
      3,
      (err) => console.error(err)
    )
  ]
})

Configuration options for browser

Optiondescription
getUrl required - functionA function that returns a string representing the url to which the payload should be sent to
maxDepth optional - numberMax depth for exponential retries. Defaults to 3
onErr optional - functionCallback for when any of the requests to your endpoint fail. Signature is (err: any) => any

Server-side usage

The Analytics Fetch server-side node.js plugin works with these analytic api methods:

Server-side API

import Analytics from 'analytics'
import analyticsFetch from "@standardorg/analytics-fetch";

const analytics = Analytics({
  app: "bookclub",
  plugins: [
    analyticsFetch(
      (action) => `https://my-tracking-url.com/${action}`,
      3,
      (err) => console.error(err)
    ),
  ],
});

Configuration options for server-side

Optiondescription
getUrl required - functionA function that returns a string representing the url to which the payload should be sent to
maxDepth optional - numberMax depth for exponential retries. Defaults to 3
onErr optional - functionCallback for when any of the requests to your endpoint fail. Signature is (err: any) => any
1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago