init & isInitialized
init
Starts tracking with the given configuration.
- Script tag: you don't call it. The tracker initialises itself with
sublim.oas 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:
- On the server (no
window), nothing happens. - 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. - On
localhost, withouttrackLocalhost: true, tracking stays off. The same goes for headless browsers. - Otherwise, tracking starts. The calls queued before
initare 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