Script Configuration

Advanced configuration options for the DataSaaS tracking script, including SPA support, outbound tracking, scroll depth, and more.

Script attributes

AttributeRequiredDescription
data-website-idYesYour unique website identifier (e.g., ds_abc123)
data-domainRecommendedYour website domain (used to validate events). If omitted, all hostnames are accepted.
data-apiNoCustom API endpoint URL. Defaults to the script's origin + /api/events.
data-allow-localhostNoSet to "true" to enable tracking on localhost / 127.0.0.1 (blocked by default).
deferRecommendedLoads the script without blocking page render

Domain validation

The data-domainattribute must match the actual hostname of the page. If there's a mismatch, events are silently dropped. This prevents unauthorized sites from sending events to your dashboard.

SPA support

DataSaaS automatically tracks navigation in Single Page Applications. No extra setup needed.

The tracking script intercepts the browser's History API:

  • pushState — Fires a new pageview when your app navigates
  • popstate — Tracks back/forward browser navigation
  • hashchange — Tracks hash-based routing (e.g., #/about)

Works automatically with:

  • Next.js (App Router and Pages Router)
  • React Router
  • Vue Router
  • SvelteKit
  • Any framework using the History API

Outbound link tracking

DataSaaS automatically detects and tracks clicks on links that point to external domains. When a visitor clicks a link where the hostname differs from the current page, an _outbound event fires with the destination URL.

View outbound data in:

  • Pages card → Exit Links tab — Which external URLs visitors click most
  • Engagement card → _outbound goal — Conversion rate and total clicks

Scroll depth tracking

DataSaaS captures scroll depth when a visitor leaves a page. When the visitor navigates away or closes the tab, a _leave event fires that includes:

  • Scroll depth — Percentage of the page scrolled (0–100%)
  • Duration — Time spent on the page in seconds

This uses the Beacon API for reliable delivery, even when the browser tab is closing.

Ad click ID tracking

Click IDs from major ad platforms are captured automatically from the URL:

PlatformParameter
Google Adsgclid
Facebook / Metafbclid
Microsoft Adsmsclkid
TikTok Adsttclid
Twitter / X Adstwclid
LinkedIn Adsli_fat_id
Google App Campaignsgbraid / wbraid

Bot filtering

The tracking script automatically skips:

  • navigator.webdriver (headless browsers)
  • __nightmare (Nightmare.js)
  • _phantom / callPhantom (PhantomJS)

Server-side bot filtering is also applied based on User-Agent patterns.

Do Not Track

DataSaaS respects the browser's Do Not Track (DNT) setting. When DNT is enabled, no events are sent.

Declarative goal tracking

Add a data-goal attribute to any HTML element to automatically fire a goal event when clicked:

<button data-goal="signup">Sign up</button>
<a href="/pricing" data-goal="view_pricing">See plans</a>

The goal fires on click and bubbles up the DOM — so it works on wrapper elements too.

JavaScript API

The tracking script exposes a window.datasaas function for programmatic use:

MethodDescription
datasaas('goal_name', meta?)Fire a custom goal event (with optional metadata)
datasaas.identify({ user_id: '...' })Associate the current visitor with a user ID in your system
datasaas.reset()Clear cookies and assign a new visitor ID (useful after logout)
datasaas.visitor_idRead the current visitor ID directly (string property)

Pre-load queue

If you need to fire goals before the script has loaded, set up a queue:

<script>
  window.datasaas = window.datasaas || function() {
    (window.datasaas.q = window.datasaas.q || []).push(arguments)
  }
  datasaas('early_goal')
</script>

Queued calls are replayed automatically once the script loads.

Cookieless mode

For stricter privacy compliance, use the cookieless variant of the tracking script:

<script
  defer
  data-website-id="YOUR_WEBSITE_ID"
  src="https://yourdomain.com/js/script.cookieless.js"
></script>

This variant uses server-side hashing (IP + User-Agent + daily salt) instead of cookies to identify visitors. No cookies are set and no client-side storage is used. Visitor identification resets daily.

Prerendering & BFCache

The script handles modern browser optimizations automatically:

  • Prerendering — If the page is prerendered (e.g., Speculation Rules API), the initial pageview is deferred until the page actually becomes visible.
  • BFCache (Back/Forward Cache) — When a page is restored from BFCache, a new pageview is fired so the visit is counted.
Note

The tracking script has zero external dependencies. It loads asynchronously and won't block your page render.