Skip to content
All documentation pages

Reference

SDK reference

What the tracker loads, what it records, and every setting you can change from the page.

What loads on a page

Tracker files
FileGzippedLoaded
b.js5.1 KBOn every page.
r.js57.2 KBOnly when the project’s plan records session replays and the page has not turned replay off.
s.js24.5 KBOnly on the page load the collector picks for a page capture, when heatmap page captures are on for the project.

b.js sends its first page view straight away, then asks the collector for the project’s settings. r.js and s.js load only once those settings arrive and allow them. If the request fails, neither loads.

The settings request also carries the page path, the screen width and a fingerprint of the layout built from tag names, never from text. The collector answers whether it still needs a capture of that page and gives it to one visitor at a time, so s.js downloads only on that page load. A new layout gets a new capture, and a layout that changes on every visit is captured at a limited rate.

Script tag attributes

Script tag attributes
AttributeDefaultWhat it does
data-keyRequiredYour project’s write key.
data-hosthttps://in.webmetric.ioThe collector events are sent to. The install panel fills in yours: https://in-stg.webmetric.io.
data-click="false"OnStops recording clicks.
data-click-labels="false"OnSends clicks without the label of the button or link. Their position and the kind of control are still recorded.
data-scroll="false"OnStops recording scroll depth.
data-replayFollows the projectfalse keeps session replay off on this page. consent loads the recorder only after consent(true).
data-snapshots="false"Follows the projectKeeps heatmap page captures off on this page.
data-mask=".a, #b"NoneMore CSS selectors, separated by commas, whose text is masked in replays and page captures.
data-hash="true"OffCounts hash changes, such as /#/pricing, as page views.
data-query="true"OffCounts query-only changes, such as ?tab=2, as page views. UTM parameters always count.
data-consent="required"OffRecords and sends nothing until consent(true) is called.
data-debug="true"OffLogs every batch, and every reason the tracker stops, to the console. Adding ?wm_debug=1 to a page address does the same for one page load.

A page can only turn replay and page captures off. Whether they run at all is decided by the project, never by the page.

init() options

init() options
OptionDefaultScript tag equivalent
keyRequireddata-key
hosthttps://in.webmetric.iodata-host
autoClicktruedata-click
clickLabelstruedata-click-labels
autoScrolltruedata-scroll
replayFollows the project. false or "consent".data-replay
snapshotsFollows the project. false turns them off.data-snapshots
maskSelectorsNone. An array of selectors.data-mask
hashfalsedata-hash
queryfalsedata-query
consentNone. "required" waits for consent.data-consent
debugfalsedata-debug
assetOriginhttps://cdn.webmetric.io/v1The directory b.js was loaded from. Where r.js and s.js load from.

The package exports init(options), track(name, props), consent(granted) and flush(). flush() sends queued events straight away instead of waiting for the next batch.

Page views and route changes

  • The first page view is recorded as soon as the tracker starts.
  • Single-page apps are covered: history.pushState, history.replaceState and the back and forward buttons each record a page view for the new route.
  • A page view is recorded only when the page changes. By default that means the path plus any UTM parameters. Turn on data-query to count every query change, and data-hash to count hash changes. Either way, the address that is sent keeps only the path and UTM parameters.
  • The referrer is sent with the first page view of a page load only, so moving around inside your app is not reported as a referral.
  • Scroll depth is the deepest point reached on each page, in steps of 10%.
  • Form submissions are described by the element’s structure (tag, id, classes and position). A click on a button, link, tab, menu item, toggle or option also carries the kind of control and its label, so reports name what was clicked. A label never comes from a form field or a masked element: see click labels.
  • Events are sent in batches: every five seconds, at 50 events, and when the visitor leaves or hides the page.

Custom events

Send an event when something happens that a page view cannot show, such as a completed sign-up.

Script tagJavaScript
window.webmetric.track("signup_completed", { plan: "growth", seats: 3 });
npmTypeScript
import { track } from "@webmetric/sdk";

track("signup_completed", { plan: "growth", seats: 3 });
  • The name is trimmed and lower-cased, then must be 1 to 64 characters of a to z, 0 to 9, underscore, dot, colon and hyphen. A name that still does not fit is dropped, with one warning in the console.
  • Properties are optional. Up to 10 are kept, with keys of up to 40 characters. Numbers and booleans become strings, values are cut to 200 characters, and anything else is left out.
  • Never put personal data, such as an email address or a name, in an event name or a property.
  • A custom event never counts as a page view. It counts as one event towards your plan.

Custom events are listed on the Events page and can be exported as CSV. Funnel steps match page views, clicks and form submissions.

Calling track() before the script loads

The script tag loads with defer, so window.webmetric does not exist until it has run. To call it earlier, for example from inline code, add this stub before the script tag. Calls made through it are sent once the tracker starts.

Before the script tagHTML
<script>
  window.webmetric = window.webmetric || {
    q: [],
    track: function () { this.q.push(arguments); },
    consent: function (granted) { this.c = granted; },
  };
</script>

With the npm package, calls to track() before init() are kept, up to 50, and sent once it runs.

Privacy defaults

  • Nothing is stored on the visitor’s device: no cookies and no browser storage.
  • A browser that sends Do Not Track or Global Privacy Control sends nothing at all.
  • Replay masks every form input in the browser, before anything is sent. Page captures mask all of the page’s text as well.
  • A click label is the visible name of a button or link, never text from a form field or a masked element, with email addresses and long numbers removed.
  • Page addresses are sent without the part after a # or any query parameter other than utm_*, and referrers as origin and path.
  • The write key is public by design. It ships in your page source, and it can only write, only to its own project.

The details are in privacy and data collection.