Two-line JavaScript tracking snippet being pasted into a website's HTML head

Snippet: How to Install statpx Tracking on Your Site

Before any of statpx's dashboards can show you data, your site needs the tracking snippet installed. The Snippet page (snippet.php) is where you get that code, verify it's working, and control the optional attribution badge — all per site, since every site has its own unique tracking ID.

Getting the Snippet

Open a site and click Snippet in the sidebar. You'll see a two-line code block unique to that site:

<script>window._stid='YOUR_TRACKING_ID';window._stendpoint='https://statpx.com';</script> <script src="https://statpx.com/track.js" async data-cfasync="false"></script>

The first line sets two global variables: window._stid (your site's tracking ID) and window._stendpoint (where track.js sends data). The second line loads track.js itself, asynchronously so it never blocks page rendering. Paste both lines before </head> or </body> — either works, since track.js waits for those globals regardless of load order. If you use a template system or CMS, add it once to your global layout so every page inherits it automatically.

Verifying the Install

After adding the snippet and visiting your own site once, come back to the Snippet page and click Verify Installation. statpx fetches your site and checks that the script is present and correctly configured, then reports success or a specific reason it couldn't find it — for example, the tracking ID not matching, or the script missing entirely. If verification fails, double-check that the snippet made it to the live page (not just a staging copy) and that no ad blocker or CSP rule is stripping the script.

Once a site is verified, statpx also rechecks periodically in the background and will notify you if the snippet ever stops responding — for example, after a site redesign accidentally drops it.

SPA Support

track.js automatically intercepts history.pushState calls, so single-page apps built with React, Vue, or similar frameworks get accurate pageview tracking on client-side route changes without any extra configuration — no manual event firing needed on every navigation. See tracking single-page apps for a deeper look at how this works and when you might still want a manual page-view call for edge cases like modal-based "pages."

The Optional Badge

Below the snippet, a checkbox lets you toggle a small "Analytics by statpx" badge that appends to the snippet code. It's a do-follow link back to statpx, and keeping it enabled is one way sites help keep statpx free — entirely optional, and toggling it updates the code block live so you can copy the exact version you want to ship.

Tip: if you need to record extra debug detail on a specific page while troubleshooting, add <script>window._stRecord = true;</script> before the standard snippet lines.

Common Mistakes to Avoid

Install statpx in under two minutes

Two lines of code, no cookie banner required, and instant verification once it's live.

Start for free →

The Bottom Line

The Snippet page is the one-time setup step every other statpx feature depends on: paste the two-line script, verify it, and you're tracking. SPA support and the optional badge round out the details, but the core steps are simple by design. Once installed and verified, head straight to Real-time to confirm your first visit is arriving, then move on to Stats as data accumulates.

Continue reading

Technical
How to Identify and Block Referrer Spam in Website Analytics
Metrics
How to Track and Reduce Shopping Cart Abandonment with Analytics
Privacy
Google Consent Mode v2 Explained: What It Means for Your Analytics
Analytics by statpx