Skip to content

SDKs

JavaScript SDK

Install the Tracklyne browser SDK, capture events, configure autocapture, persistence and privacy options.

Install

Use the script tag, or the npm package with a bundler. Both expose the same methods; the script tag puts the instance on window.tracklyne.

Terminal
npm install @tracklyne/js
app.ts
import tracklyne from "@tracklyne/js";

tracklyne.init("tl_your_project_token", {
  api_host: "https://tracklyne.com",
  capture_pageview: "history", // also on client-side navigation (SPAs)
  persistence: "cookie",       // "cookie" | "localStorage" | "memory"
});
OptionDefaultWhat it does
autocapturetrueClicks, form submits and changes
capture_pageviewtrue"history" also captures on pushState and popstate
capture_exceptionstrueUnhandled errors and rejections go to error tracking
enable_heatmapstrueClick positions for heatmaps
disable_session_recordingfalseReplay is also controlled from project settings
mask_all_inputstrueMasks every input in replays
disable_surveysfalsePopover surveys
opt_out_by_defaultfalseSend nothing until opt_in_capturing()

With the script tag, use data attributes: data-persistence="memory", data-capture-pageview="history", data-autocapture="false"…

Capture events

Name events after what the user did, in the past tense, and attach the properties you will want to break down by later.

app.ts
tracklyne.capture("project created", { template: "blank", members: 3 });

tracklyne.register({ app_flavor: "beta" }); // super properties, sent with every event

Cookies and persistence

ModeStoresUse when
cookie (default)Ids and flags in a first-party cookie tl_<token> on your top domainVisitors should be recognised across subdomains and visits
localStorageThe same state in local storageOne domain, no cookie
memoryNothing; a new anonymous id per page loadYou do not want a cookie banner for analytics

Opt out and privacy

app.ts
tracklyne.opt_out_capturing(); // stop sending anything from this browser
tracklyne.opt_in_capturing();  // resume

Add the class tl-no-capture (or the attribute data-tl-no-capture) to an element to exclude it, and its children, from autocapture, heatmaps and replays. Text that looks like a card number is never captured.

Errors

Unhandled errors and promise rejections are sent as $exception events. Report caught errors yourself:

checkout.ts
try {
  await checkout();
} catch (err) {
  tracklyne.captureException(err, { step: "payment" });
}