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.
| Attribute | What it does |
|---|---|
data-website-id | Required. Your site id. |
data-api | Send events to another address, for example your own domain. See Use your own domain. |
data-vitals | Page speed from real visits (LCP, INP, CLS, FCP, TTFB) for the Performance page. |
data-errors | Uncaught JavaScript errors and rejected promises for the Errors page. Emails and secrets are removed first. |
data-downloads | A file_download goal for links to files such as pdf, zip, csv or dmg. |
data-404 | A 404 goal on pages that carry <meta name="earnedstats:404">. |
data-hash | Counts the route after # as the page, for apps with URLs like /#/pricing. |
data-manual | No automatic pageviews. Call earnedstats("pageview") yourself. |
data-allow-localhost | Count visits from localhost and .local addresses. |
data-debug | Log 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
| Call | What 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); };