SublimDocs

init & isInitialized

init

Starts tracking with the given configuration.

  • Script tag: you don't call it. The tracker initialises itself with sublim.o as soon as it loads.
  • npm: call it once, on the client, as early as possible.
JavaScript
import { init } from '@sublim_analytics/tracker';

init({ projectId: 'YOUR_PROJECT_ID' });
TypeScript
init(options?: SublimOptions): void

What happens on init:

  1. On the server (no window), nothing happens.
  2. If the page is already tracked, by an earlier init() or by the CDN snippet, the call is ignored. You get a console warning, and nothing is counted twice.
  3. On localhost, without trackLocalhost: true, tracking stays off. The same goes for headless browsers.
  4. Otherwise, tracking starts. The calls queued before init are sent, then the pageview of the current page.

Loading the bundle without the snippet

If you add the bundle with a plain <script src="…/sublim.min.js"> and no sublim.o, nothing starts until you call sublim.init({ projectId: '…' }) yourself. The official snippet sets sublim.o, so this doesn't apply to it.

isInitialized

npm only. Returns true when the page is being tracked, by this package or by the CDN snippet.

JavaScript
import { isInitialized } from '@sublim_analytics/tracker';

if (!isInitialized()) {
  init({ projectId: 'YOUR_PROJECT_ID' });
}
TypeScript
isInitialized(): boolean