How to Add Website Analytics to Any Platform or CMS
Every web analytics tool works the same way at its core: a small JavaScript snippet runs on your pages and sends visit data to the analytics server. The tracking snippet is always the same two lines of code. The only thing that changes is how you add it to your specific platform.
This guide covers the right way to add statpx tracking to the most common platforms — from plain HTML files to WordPress, Shopify, Next.js, and website builders — so you can get accurate data flowing in under five minutes regardless of how your site is built.
The Two-Line Snippet
Your statpx tracking snippet is always two script tags. You'll find your personal version on your site's Settings page after adding a site, but the pattern looks like this:
The first line initializes the _st() function immediately so any calls you make before the script loads are queued. The second line loads the tracker asynchronously — the async attribute means it never blocks page rendering. Once the tracker loads, it fires an automatic pageview and processes any queued calls.
Replace YOUR_TRACKING_ID with the tracking ID from your dashboard. That ID is how statpx knows which site and account to attribute the data to.
Platform-by-Platform Setup
HTML / PHP sites
For static HTML or PHP-based sites, open your main template file — the one that outputs the closing </body> tag shared across all pages. This is typically footer.php, layout.php, or a shared include file. Paste the two snippet lines immediately before </body>. Because the template is shared, every page will include the snippet automatically.
If your site doesn't use a shared template and each page is a separate file, you'll need to add the snippet to each file individually — or, better, refactor your footer into a shared include first. Partial coverage produces inaccurate data, particularly for bounce rates and session paths.
WordPress
The recommended approach for WordPress is the official statpx plugin, available from your dashboard's Integrations page. Install and activate it, paste your tracking ID into the plugin settings, and tracking starts immediately on all pages including the homepage, blog posts, and WooCommerce pages.
If you prefer not to use a plugin, open your active theme's footer.php file via Appearance → Theme File Editor and paste the snippet before </body>. Note that theme updates can overwrite this file — use a child theme if your theme updates frequently. A third option is a code snippet plugin (such as WPCode), which lets you add custom code without editing theme files directly.
Shopify
In your Shopify admin, go to Online Store → Themes → Edit code. Open theme.liquid — this is the global layout file that wraps every page in your store. Paste the snippet immediately before the closing </body> tag and click Save. Shopify applies this file to all storefront pages, so a single paste covers your homepage, product pages, collection pages, and checkout confirmation page.
Next.js / React
For Next.js (Pages Router), add the snippet to pages/_app.js using a useEffect hook to ensure it runs after the component mounts. For Next.js App Router, add it to app/layout.tsx using the built-in Script component with strategy="afterInteractive":
For single-page applications where navigation happens client-side without full page reloads, you'll also need to manually fire pageview events on route changes. See our dedicated guide on tracking analytics in single-page apps for the full pattern.
Webflow / Framer / Squarespace / Wix
Website builders all provide a designated area for custom code. The location varies by platform:
- Webflow — Project Settings → Custom Code → Footer Code
- Framer — Site Settings → Custom Code → End of <body>
- Squarespace — Settings → Advanced → Code Injection → Footer
- Wix — Settings → Custom Code → Add Custom Code → Body (End)
In each case, paste the two-line snippet into the footer code field and save. The builder injects it into every page automatically.
The Golden Rule: Track Every Page
A partial install — where the snippet is present on some pages but not others — is worse than no install at all. When visitors land on an untracked page and then navigate to a tracked one, statpx sees the tracked page as a new session start with no referrer context. Your bounce rate will be artificially inflated, your session counts will be wrong, and your most popular pages might not even be tracked.
Before considering your setup complete, check that your snippet is loading on: your homepage, at least one blog post, your pricing page, your signup/registration page, and your 404 page. If any of these are missing the snippet, find the layout or template file they use and add it there.
Verifying Your Install
After adding the snippet, visit your site in a browser and then return to your statpx dashboard. Your site's card on the dashboard will have a Verify button — click it to trigger an automated check that confirms the tracker is loading and reporting correctly. You can also watch the Real-time view, which updates every few seconds and will show your visit immediately if the snippet is firing.
If the verify check fails, the most common causes are: the snippet is only on some pages (see the golden rule above), a Content Security Policy is blocking the tracker script, or the tracking ID was pasted incorrectly. The statpx user guide has a full troubleshooting section covering each of these scenarios.
Two lines of code. Every platform. Free analytics from day one.
Sign up, add your site, copy your snippet, and paste it into your template. That's everything. No tag managers, no configuration screens, no credit card.
Get started free →The Bottom Line
Installing analytics correctly comes down to one principle: put the snippet in the shared template file that renders on every page, and verify it's working before you rely on the data. Whether you're using a hand-coded PHP site, a WordPress theme, a Shopify store, or a no-code builder, the method is always the same — find the global footer, add two lines, confirm. Once the snippet is in place and verified, everything statpx can do — pageview tracking, session analysis, custom events, referrer data, real-time visitors — works automatically without any additional setup.