Get started
Install the Loogika tracking script
The tracking script is one tag that you add to the head of your site. It records pageviews and events and sends them to Loogika. This page shows the tag and every option you can set on it.
Last updated . This guide belongs to Cookieless tracking.
How do you install the script?
Add this tag inside the head element of every page you want to track. Replace YOUR_SITE_ID with the ID from your site settings.
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
The site ID sits in the URL on purpose. Caching plugins and tag managers sometimes remove data attributes from script tags, and a query parameter survives that.
An older form with data-site-id="YOUR_SITE_ID" still works. Use the URL form for new installs.
Which settings live in the dashboard?
Most tracking behaviour is set per site in Site Settings. The script fetches these settings when it loads, so you change them without touching your code.
| Setting | Where | On for a new site | What it controls |
|---|---|---|---|
| Initial Page View | Tracking | Yes | Whether the script records a pageview when a page loads |
| SPA Navigation | Tracking | Yes | Whether route changes in a single-page app count as pageviews |
| URL Parameters | Tracking | Yes | Whether query strings are kept in the tracked URL |
| Web Vitals | Tracking | No | Loading and responsiveness metrics per page |
| Session Replay | Tracking | No | Recordings of individual visits |
| Outbound Links | Tracking, Auto Capture | Yes | Clicks on links to other domains |
| Error Tracking | Tracking, Auto Capture | No | Uncaught JavaScript errors |
| Button Clicks | Tracking, Auto Capture | No | Clicks on buttons |
| Copy Events | Tracking, Auto Capture | No | Text that visitors copy |
| Form Interactions | Tracking, Auto Capture | No | Form submissions and changed fields |
| Block Bot Traffic | General | Yes | Whether known bots are kept out of the reports |
Which attributes can you set on the script tag?
| Attribute | Value | Default | What it does |
|---|---|---|---|
data-skip-patterns | JSON array of paths | [] | Pages that match are not tracked |
data-mask-patterns | JSON array of paths | [] | Pages that match are tracked, but the report shows the pattern in place of the real path |
data-debounce | Milliseconds | 500 | How long the script waits after a route change before it records a pageview. 0 turns the wait off |
data-tag | Text, up to 256 characters | Empty | A label added to every event from this script. See Tagging |
This example skips the admin area and hides user IDs in profile paths:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID"
data-skip-patterns='["/admin/**"]'
data-mask-patterns='["/users/*/profile"]'
defer></script>
How do path patterns work?
Skip and mask patterns use the same syntax.
| Pattern | Matches | Example |
|---|---|---|
* | Any characters inside one path segment | /blog/*/comments matches /blog/post-123/comments |
** | Any characters across several segments | /admin/** matches every page under /admin/ |
re: | A regular expression, used as written | re:^/order/\d+$ matches /order/4821 |
A regular expression matches anywhere in the path unless you add ^ and $.
How does tracking work in a single-page app?
A single-page app changes the URL without loading a new page. With SPA navigation turned on, Loogika records a pageview when the path or a tracked query string changes.
The script waits 500 milliseconds after a route change before it records the pageview. That keeps redirects inside the app from counting twice. Change the wait with data-debounce.
Hash routes that start with #/ count as paths, so /#/shipping is reported as /shipping. Other fragments, such as #shipping, are ignored.
If you turn SPA navigation off, record pageviews yourself:
window.loogika.pageview();
Which session replay options can you set?
These attributes only take effect when session replay is turned on in Site Settings.
| Attribute | Default | What it does |
|---|---|---|
data-replay-mask-all-inputs | true | Hides the value of every input field |
data-replay-mask-input-options | {"password":true,"email":true} | Input types that are always hidden. Add more, for example "tel":true |
data-replay-mask-text-class | rr-mask | Elements with this class have their text replaced by asterisks |
data-replay-mask-text-selectors | [] | CSS selectors for elements whose text is hidden |
data-replay-block-class | rr-block | Elements with this class are left out of the recording |
data-replay-block-selector | None | A CSS selector for elements to leave out |
data-replay-ignore-class | rr-ignore | The element is shown, but typing in it is not recorded |
data-replay-ignore-selector | None | The same, chosen with a CSS selector |
data-replay-collect-fonts | true | Stores your web fonts so the replay looks like the page. Set to false to store less data |
data-replay-sampling | See below | How often mouse, scroll and input activity is recorded |
data-replay-slim-dom-options | See below | Parts of the page that are left out to keep recordings small |
By default the recording stores clicks, double clicks, focus and blur. It does not store mouse movement. Scroll positions are sampled every 500 milliseconds, and only the last value typed in a field is kept.
Questions about the tracking script
Does the script slow the page down?
The tag uses defer, so the browser renders your content before it runs the script.
Can ad blockers stop the script?
Yes. Some ad blockers and privacy extensions block analytics scripts. You can load the script through a proxy on your own domain. The proxy must pass on the visitor's address in X-Real-IP or X-Forwarded-For, and First-Party Proxy must be on in Site Settings.
Where do you find the site ID?
Open Site Settings in the dashboard. The script tag shown there already contains the ID.