Add the tracking snippet to your website

To start collecting analytics data, you need to add the Pageviews tracking snippet to your website. The snippet is a small piece of JavaScript that sends anonymous pageview data to your Pageviews dashboard.

Copy your tracking snippet

You can find your tracking snippet in two places:

  • During the onboarding flow after adding your site.
  • In your Site Settings → General page at any time.

{screenshot: tracking snippet in site settings}

Your snippet will look something like this:

<script src='https://pageviews.ai/{site_id}.js' async></script>

Install the snippet

Paste the snippet into the <head> section of your website's HTML. It should be present on every page you want to track.

Static HTML sites

Add the snippet directly to your index.html (or your shared layout/header file) inside the <head> tag.

WordPress

You can add the snippet using a plugin like Insert Headers and Footers, or by editing your theme's header.php file.

Single-page applications (React, Vue, Next.js, etc.)

For SPAs, we recommend using the @pageviews/tracker NPM module instead of the script tag. It gives you full programmatic control, proper lifecycle management, and tree-shaking support.

npm install @pageviews/tracker

See the NPM module (@pageviews/tracker) article for full installation and usage instructions.

Alternatively, you can add the script tag to your index.html or app shell — Pageviews automatically detects client-side navigation using the History API.

Other platforms

For platforms like Shopify, Squarespace, Webflow, or Ghost, look for the "Custom Code" or "Code Injection" section in your platform's settings and paste the snippet there.

Important notes

  • The async attribute ensures the script loads asynchronously and won't block your page rendering.
  • The script is less than 1KB in size — it will have no measurable impact on your page load speed.
  • The {site_id} in the snippet URL is your unique site identifier, which you can find in your site settings.