JAVASCRIPT SDK

Getting started with Asayer JavaScript SDK.

Installation

npm i @asayerio/tracker --save

Usage

Initialize the package from your codebase entry point and start the tracker. You must set the projectID option in the constructor. Its value can be found in your Asayer dashboard under Preferences > Projects.

import Tracker from '@asayerio/tracker';
const tracker = new Tracker({
projectID: PROJECT_ID
});
tracker.start();

Methods

Check our API documentation for the list of methods you could use, such as for identifying users. Below is an example:

tracker.userID('john@doe.com');

Options

There are a set of options you can pass to the constructor. Only projectID is required.

General Purpose

  • projectID: number The ID of the project you're tracking.
  • sessionID?: string The ID of the initial session. This is useful when sessions traverse different subdomains on your web app but you want to stitch them into a single recording. In case it's not possible to continue the session (doesn't exist or is finished), the tracker will start a new one.
  • revID?: string The revision ID of your web app. Useful when searching for issues happening on a specific release version.
  • consoleMethods: Array<'log' | 'info' | 'warn' | 'error'> | null The list of console methods to capture. Default: ['log', 'info', 'warn', 'error']
  • consoleThrottling?: number Max number of console entries per second. Default: 30.
  • captureExceptions?: boolean Capture JavaScript exceptions and stacktraces. Default: true.
  • captureResourceTimings?: boolean Log resource timings. Default: true.
  • capturePageRenderTimings?: boolean Compute page rendering metrics such as Speed Index, Visually Complete or Time To Interactive. Requires captureResourceTimings = true. Default: true.

Sanitizing Data

  • obscureTextEmails?: boolean Obscure emails in text. Emails will be converted to a random number of asterisks. Default: true.
  • obscureTextNumbers?: boolean Obscure numbers in text. Numbers will be converted to a random number of asterisks. Default: false.
  • obscureInputEmails?: boolean Obscure emails in input fields. Email values will be converted to a random number of asterisks. Default: true.
  • defaultInputMode?: 0 | 1 | 2 Default capture mode for input values. Respectively: plain, obscured or suppressed. Default: 0 (plain).

Sanitized text, email and numbers are obscured or suppressed before sending the data to our servers. Therefore, changes applied to the above options cannot be retroactive and will only apply to newly collected data.

Misc

See d.ts files inside the package for the list of available options and functions.