Install the script
The snippet, its options, single-page apps, custom events and identify.
Add one tag to the <head> of every page. Your site id is on the site's Setup page.
<script defer data-site="pr_..." src="https://pathrail.io/js/script.js"></script>
The script is about 3.6 KB gzipped. It counts pageviews, follows client-side navigation (history.pushState and back/forward), and records outbound link clicks and file downloads as events.
Options
| data-cookieless | Store nothing in the browser. Visitors are counted from a daily rotating hash instead, so returning-visitor and multi-day journeys are less precise. |
| data-hash | Count changes to the #fragment as pageviews, for hash-routed apps. |
| data-allow-localhost | Send hits from localhost. Also add localhost under Other hosts in the site's settings. |
| data-api | Send hits to a different endpoint, for a first-party proxy. |
To stop counting your own visits, run localStorage.pathrail_ignore = "1" in the browser console, or use Ignore my network in settings.
Custom events
Add this before the script tag so calls made before it loads are queued, not lost:
<script>window.pathrail=window.pathrail||function(){(pathrail.q=pathrail.q||[]).push(arguments)}</script>pathrail("signup")
pathrail("signup", { plan: "pro" }) // with properties
pathrail("purchase", {}, { revenue: 49, currency: "USD" }) // only if no provider is connectedOr with no JavaScript: give any element data-pathrail-event="signup" and properties as data-pathrail-prop-plan="pro". A click sends the event.
Identify people
When someone signs in or signs up, tell Pathrail who they are. Their earlier anonymous visits, their other devices and payments made with that email all join up.
pathrail("identify", { email: user.email, user_id: user.id })Emails are stored as a per-site hash, never in plain text.