How to install the Traffic Tracker code on your website
Where to find your tracking snippet, where to paste it on WordPress, Wix, Shopify, Squarespace or plain HTML, and how to check that visits are counted.
By the Traffic-Key SEO team5 min read
The Traffic Tracker counts the visits to your website with a small piece of code, called a snippet. You paste it once, and from then on every page that carries it is counted. This guide shows where to find the snippet, where to paste it on the most common website builders, and how to check that it works.
What the snippet looks like
Your own snippet is in your dashboard, on the Traffic Tracker page. It contains your personal site ID. This is an example with a made-up ID:
<script>
(function () {
var SITE_ID = "YOUR_SITE_ID";
var ENDPOINT = "https://www.traffic-key-seo.com/api/collect";
try {
var vid = localStorage.getItem("_ttseo_vid");
if (!vid) {
vid = Math.random().toString(36).slice(2) + Date.now().toString(36);
localStorage.setItem("_ttseo_vid", vid);
}
fetch(ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json" },
keepalive: true,
body: JSON.stringify({
siteId: SITE_ID,
path: location.pathname,
referrer: document.referrer,
visitorId: vid,
}),
});
} catch (e) {}
})();
</script>Don't copy this example, because it will not count anything. Copy the snippet from your own dashboard, which has your real site ID.
Where to paste it
Paste the snippet into the head of your pages, just before the closing </head> tag, on every page you want counted. Most website builders have a place for it:
- WordPress: use a plugin that adds code to the header (a "header and footer" plugin), or paste it into your theme's header file before </head>. A change in a theme file can be lost when the theme is updated, so a plugin or a child theme is safer.
- Wix: open Settings, then Custom Code, add new code, paste the snippet, choose "Head" and apply it to all pages.
- Shopify: open Online Store, then Themes, then Edit code, open theme.liquid and paste the snippet just before </head>.
- Squarespace: open Settings, then Advanced, then Code Injection, and paste the snippet in the Header box. Code injection needs a paid Squarespace plan.
- A plain HTML site: open the shared header file, or each page, and paste the snippet before </head>.
Menu names change from time to time. If you can't find the place, search your website builder's help for "custom code in the head".
Check that it works
- Save and publish your changes.
- Open your website in a new tab and visit a page, using the address you registered in your dashboard.
- Open the Traffic Tracker in your dashboard. Your visit should appear within seconds.
- If nothing appears, go through the list below.
If visits don't appear
- The snippet is on a different website. Visits are counted only from pages on the website registered for your site ID, and its subdomains. A page on another domain is refused. Install the snippet only on the website you registered; to change the registered website, contact support.
- The page is cached. A caching plugin or your host may keep serving the old page. Clear the cache and reload.
- An ad blocker or a privacy extension may block the script in your own browser. Try another browser or a private window.
- The visit came from a crawler or a checker. Automated visits, such as search engine bots and site checkers, are not counted.
- The snippet was changed. Copy it again from your dashboard, exactly as it is.
Good to know
- The snippet stores a random visitor ID in the visitor's browser (in localStorage, not a cookie) and collects no IP addresses. Tell your visitors what you collect where the law requires it.
- Each website has a monthly limit on recorded page views, stated in the Terms of Service.
- Visits from your own computer are counted like any other, so they can inflate the numbers in the first days.
Next, read how to track website traffic to learn which numbers to watch, or see a sample report.
Want to see this for your own website?
Look at a sample report first, or create an account and connect your website.