EarnedStats Docs

Install

Script options

Every attribute the script tag understands.

Add attributes to the tag to turn on extra tracking. Settings, Tracking builds the tag for you with switches.

AttributeWhat it does
data-website-idRequired. Your site id.
data-apiSend events to another address, for example your own domain. See Use your own domain.
data-vitalsPage speed from real visits (LCP, INP, CLS, FCP, TTFB) for the Performance page.
data-errorsUncaught JavaScript errors and rejected promises for the Errors page. Emails and secrets are removed first.
data-downloadsA file_download goal for links to files such as pdf, zip, csv or dmg.
data-404A 404 goal on pages that carry <meta name="earnedstats:404">.
data-hashCounts the route after # as the page, for apps with URLs like /#/pricing.
data-manualNo automatic pageviews. Call earnedstats("pageview") yourself.
data-allow-localhostCount visits from localhost and .local addresses.
data-debugLog each event in the console and send nothing.
All extras on
<script defer data-website-id="YOUR_SITE_ID"
  data-vitals data-errors data-downloads
  src="https://earnedstats.com/js/script.js"></script>

The earnedstats function

CallWhat it does
earnedstats('goal', name, props)Counts a goal. See Goals.
earnedstats('identify', { user_id, email, name })Names the current visitor. See Identify users.
earnedstats('pageview')Sends a pageview now (for data-manual).
earnedstats.attribution()Returns { es_visitor_id } to pass to your checkout.
Note

Calls made before the script loads are kept and sent once it does, if you add this stub before your own code: window.earnedstats = window.earnedstats || function () { (window.earnedstats.q = window.earnedstats.q || []).push(arguments); };