Browser snippet

A script of about 1.5 KB with no dependencies. It records page views on your docs and sites, and links them to the account a visitor later signs in to.

Install

Snippet
<script src="https://usetamari.com/snippet.js" data-write-key="YOUR_WRITE_KEY" async></script>

Add it to every page you want counted. It records a page view on load, and again when a single-page app changes path. Changes to the query string or the # fragment alone are not new page views.

To send data to a different Tamari address than the one the script loads from, add data-api-url.

Link visitors to accounts

Identify
// After your sign-in, so earlier anonymous visits count for this person
window.tamari.identify({ userId: user.id, email: user.email });

Call it after sign-in on any page that has the snippet, with your user ID, email address, or both. Earlier anonymous page views from that browser are then credited to the developer. Your backend can do the same with POST /api/v1/identify.

What it sends

  • The page's address without its query string or fragment, and its title.
  • The address of the page the visitor came from, also without query string or fragment.
  • utm_source, utm_medium, utm_campaign and tm_click, when the address has them.
  • A random visitor ID and the time.

It does not fingerprint browsers, read form fields, or record clicks or scrolling.

Privacy and opt-out

  • Browsers with Do Not Track or Global Privacy Control turned on send nothing, and no ID is stored.
  • window.tamari.optOut() stops tracking in that browser, deletes the visitor ID, and is remembered. Offer it from your cookie banner or privacy page.
  • The visitor ID is kept in a first-party cookie, tamari_anon, for up to a year, on your registrable domain, so docs.example.com and app.example.com share it. It falls back to localStorage where cookies are blocked.

You are responsible for telling your visitors about the cookie, and for any consent your law requires.

Testing

Open a page with the snippet in a normal browser window, without Do Not Track. The page view reaches Tamari within seconds, and the setup checklist ticks. Ad blockers can block analytics scripts; test with them off.

Browser snippet · Tamari docs