Tracking

Tracking Snippet

In short

A tracking snippet is a short piece of JavaScript in your website's head that records page views and events and sends them to analytics or advertising tools.

Also known as: tracking code, tracking script

A tracking snippet is a short block of code, usually JavaScript, that you paste into your website's source. It records page views and user actions and sends them to an analytics or advertising tool.

How does a tracking snippet work?

You copy the tracking code from your tool and paste it into the head section of your site. When a page loads, the browser fetches the actual script, often asynchronously so the page is not blocked. The script then registers page views, clicks or form submissions and sends them on.

Common examples include the Meta Pixel, the Google Tag and the container code of Google Tag Manager. Each of them is a form of client-side tracking.

Why does the tracking snippet matter?

No snippet, no data. It is the starting point for conversion tracking, retargeting and site analytics. How your snippets are organised also decides how much maintenance you face and how clean your data is:

  • Many separate snippets (one per platform) quickly lead to clutter, duplicate events and slower pages.
  • A tag manager bundles snippets but comes with its own learning curve.
  • One central script that serves every platform reduces the work to a single install.

Mind privacy rules

A tracking script that sets marketing cookies or sends data to ad platforms should only become active after consent in the EU. Your cookie banner has to control which parts of the snippet load and when. Read more in the guide to GDPR-compliant tracking.

Example

An agency manages ten client websites. Instead of maintaining the Meta Pixel, LinkedIn Insight Tag and Google Tag separately on each site, it installs one central snippet per website. New platforms or events are then added in the app without touching the site code again.

Tracking snippets with LeadSignal

With LeadSignal you need exactly one tracking snippet in your site's head. No npm package, no build step and no developer for later changes. During onboarding, LeadSignal checks live whether the snippet is installed correctly. From then on it records page views automatically, including route changes in single-page apps, detects form fields and ships its own cookie banner. Ad platforms are connected with a few clicks in the app.

Frequently asked questions

Where do I put a tracking snippet?+

Usually in the head section of your site so it loads early on every page. WordPress, Webflow, Wix and Shopify all offer a field for custom header code.

Does a tracking snippet slow down my website?+

A single script loaded asynchronously has very little impact on load time. Performance problems tend to appear when many different pixels and tags load at once.

Guides on this topic

Articles on this topic

Related terms