traffic.cx documentation
Install traffic.cx & Verify Your First Visit
Add your site's tracking script, check that visits arrive, handle single-page navigation and troubleshoot common installation problems.
Updated 14 October 2026
You need a traffic.cx account, a site you can edit, and access to publish its HTML. Start with the trial or a paid plan, then follow these steps before connecting payments.
1. Add your site
Open the traffic.cx dashboard, select your team and add the website you want to measure. Enter its real domain. Complete the setup flow, or open the site's Settings → Tracking to find its installation snippet.
Each site has its own public ID and script URL. Copy the snippet from the dashboard; the placeholder below will not collect visits for your account.
2. Install the script once
Place the script in the shared HTML <head> so it loads on every page:
html
<script defer src="https://traffic.cx/js/YOUR_SITE_ID.js"></script>Replace YOUR_SITE_ID with the complete ID from your dashboard, including its tcx_ prefix. Keep the script hosted at traffic.cx so it receives your site's tracking settings. Do not add a second copy through a tag manager or component.
- Plain HTML: use your shared template, or add it to every HTML page if there is no shared template.
- React or Vue with Vite: put it in the root
index.html, inside<head>. - SvelteKit: put it in
src/app.html, inside<head>, alongside the existing head placeholder. Keep the rest of that file intact. See SvelteKit's app template documentation. - A CMS or website builder: use its shared head-code setting. Publish the change and clear any page cache.
Use a normal external script, not type="module". The tracker already follows history.pushState and browser back/forward navigation. Do not add another pageview call on each SPA route change. Query-string-only changes do not create a new pageview; hash routes need the hash-routing option in Tracking settings.
3. Verify your first visit
- Publish the site and open its public URL in a normal browser tab. Visit a second page too.
- In developer tools, open Network. Your site's
/js/tcx_….jsrequest should return JavaScript with status 200. An event request goes tohttps://traffic.cx/api/event. - In the site's Settings → Tracking, select Check installation. It checks the homepage for the snippet and reports whether an event has arrived.
- Open the realtime dashboard. Confirm that your page appears and then check the usual traffic report. Allow a short delay for collection and report updates.
An accepted network request alone does not prove that a visit was recorded: filtered events can also receive an accepted response. Confirm the event in the dashboard. Do not use automated browser traffic as your first-visit check; the tracker intentionally ignores it.
4. Check a custom event
After the script has loaded, run this in your browser console or attach it to a real action:
js
window.trafficcx?.('signup_started', {
props: { plan: 'starter' },
});The custom event uses the current visit. To report it as a goal, create a matching custom-event goal named signup_started in the dashboard. Use non-personal property values; avoid names, email addresses and secrets in URLs or event properties. Pageviews and custom events count toward your event allowance.
Troubleshooting
| Symptom | What to check |
|---|---|
| Script returns 404 or HTML | Copy the full per-site /js/tcx_….js URL from Settings. /script.js is not the installation URL. Confirm that the site ID belongs to this site. |
| Script is blocked | Check the browser's blocker and your Content-Security-Policy. Allow https://traffic.cx in both script-src and connect-src, preserving the rest of your policy. |
| No visits on localhost | Localhost, file URLs and iframes are ignored by default. Verify on your published domain. |
| No visits from this browser | Check whether this browser was excluded in Tracking settings. Also check excluded paths, the team's trial/usage limit and whether the site is active. |
| Duplicate visits | Remove duplicate script tags or tag-manager installs, and remove manual route pageview calls. |
| Installation check misses a working script | It inspects the homepage HTML. A script injected later by a framework may not appear there; check the Network panel and the latest received event as well. |
| Pageview ID is missing | Wait for the script to load and the first eligible pageview. A blocked or excluded visit may not have an ID. |
For additional logging, turn on the site's temporary debug mode in Settings → Tracking and reload the page. Check the console for traffic.cx messages. Debug mode does not bypass the normal exclusions.
Next: connect your payments
Read how revenue attribution works, then follow the guide for Stripe, Dodo Payments, Lemon Squeezy or Polar. Connecting a provider imports payments; passing the visit's identifiers into checkout links those payments to your traffic.
Need another provider? Use the Payments API. If you only control the thank-you page, see purchases from the script.