Documentation menuGet started: Tracking script

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.

SettingWhereOn for a new siteWhat it controls
Initial Page ViewTrackingYesWhether the script records a pageview when a page loads
SPA NavigationTrackingYesWhether route changes in a single-page app count as pageviews
URL ParametersTrackingYesWhether query strings are kept in the tracked URL
Web VitalsTrackingNoLoading and responsiveness metrics per page
Session ReplayTrackingNoRecordings of individual visits
Outbound LinksTracking, Auto CaptureYesClicks on links to other domains
Error TrackingTracking, Auto CaptureNoUncaught JavaScript errors
Button ClicksTracking, Auto CaptureNoClicks on buttons
Copy EventsTracking, Auto CaptureNoText that visitors copy
Form InteractionsTracking, Auto CaptureNoForm submissions and changed fields
Block Bot TrafficGeneralYesWhether known bots are kept out of the reports

Which attributes can you set on the script tag?

AttributeValueDefaultWhat it does
data-skip-patternsJSON array of paths[]Pages that match are not tracked
data-mask-patternsJSON array of paths[]Pages that match are tracked, but the report shows the pattern in place of the real path
data-debounceMilliseconds500How long the script waits after a route change before it records a pageview. 0 turns the wait off
data-tagText, up to 256 charactersEmptyA 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.

PatternMatchesExample
*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 writtenre:^/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.

AttributeDefaultWhat it does
data-replay-mask-all-inputstrueHides 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-classrr-maskElements 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-classrr-blockElements with this class are left out of the recording
data-replay-block-selectorNoneA CSS selector for elements to leave out
data-replay-ignore-classrr-ignoreThe element is shown, but typing in it is not recorded
data-replay-ignore-selectorNoneThe same, chosen with a CSS selector
data-replay-collect-fontstrueStores your web fonts so the replay looks like the page. Set to false to store less data
data-replay-samplingSee belowHow often mouse, scroll and input activity is recorded
data-replay-slim-dom-optionsSee belowParts 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.