Tracking script

This is the complete reference for the tracking snippet and what you can do with it. For the guided first-time walkthrough, see Install the tracking snippet.

The snippet

Each site has its own snippet with a unique script URL. Paste it into the <head> of every page — copy the exact one from your dashboard’s Install step:

<!-- Privacy-friendly analytics by Wazlytics -->
<script async src="https://wazlytics.com/js/wa-XXXXXXXX.js"></script>
<script>
  window.wazlytics = window.wazlytics || function(){(wazlytics.q = wazlytics.q || []).push(arguments)};
  wazlytics.init = wazlytics.init || function(o){ wazlytics.o = o || {} };
  wazlytics.init()
</script>

The first line loads the tracker asynchronously. The inline stub queues any calls you make before the script finishes loading, then wazlytics.init() starts it. Pageviews are tracked automatically once it’s on the page.

Custom events

Call wazlytics() with an event name and optional properties to record any action you care about:

wazlytics('Signup', { props: { plan: 'pro' } })

Turn an event into a measurable conversion by creating a goal for it in Settings → Goals. You can also trigger an extra pageview manually with wazlytics('pageview').

Manual tagging

Instead of writing JavaScript, you can tag any element — a button, link, or form — with a data-waz-event attribute. Wazlytics fires that event when the element is clicked (or the form is submitted):

<button data-waz-event="Signup">Create account</button>

If you can’t add attributes, a class token works too: class="waz-event-name=Signup". Tagged elements take precedence over the automatic outbound-link and download capture.

Custom properties

Attach extra detail to an event with properties. In JavaScript, pass a props object; on a tagged element, add a data-waz-props attribute containing JSON:

<a href="/pricing"
   data-waz-event="Pricing click"
   data-waz-props='{"location":"navbar"}'>Pricing</a>

Hash-based routing

Wazlytics tracks route changes in single-page apps automatically through the History API, so most React, Vue, and similar apps need nothing extra. If your app routes with the URL hash (for example /#/dashboard), enable hash routing in your init call:

wazlytics.init({ hashBasedRouting: true })

See Single-page apps for the full picture.

404 error pages

Wazlytics doesn’t guess which pages are errors, so 404s take one extra step. On your site’s 404 template, fire a custom event:

wazlytics('404', { props: { path: location.pathname + location.search } })

Then create a goal for the 404 event so you can see your broken URLs in the dashboard.

Exclude your own visits

To stop Wazlytics from counting your own browsing on a site, run this once in your browser’s console:

localStorage.setItem('wazlytics_ignore', 'true')

Note

The opt-out is per-browser and per-device. Remove it any time with localStorage.removeItem('wazlytics_ignore').