What tracking codes do
- Record page views, clicks, scrolling, form submissions and purchases as events.
- Tell ad platforms which clicks led to conversions, so they can report results and optimize bidding.
- Build audiences for remarketing.
How to add them
- Google Tag Manager: one container on the site that loads and manages all your tags, without editing the code for every change.
- Directly in the site’s code: usually in the
<head>, as each platform’s instructions describe. - Plugins or built-in integrations in your CMS or shop platform.
Good practice
- Only load tracking codes after visitors consent where the law requires it, for example with a consent banner and Google Consent Mode in the EU and UK.
- Test with Tag Assistant and each platform’s debugging tools after every change.
- Remove codes for tools you no longer use; each one slows the site down.
- Don’t send personal data, such as email addresses, in page URLs or events.
“Tracking code” can also mean a UTM code: parameters added to a link to show which campaign a visitor came from.
Tracking code example
A shop adds the Google tag through Google Tag Manager. In the container, it creates tags for GA4 page views, a purchase event and a Google Ads conversion. A test in preview mode shows that the purchase tag fires on the thank-you page with the order value. The team also adds the Meta Pixel with the same trigger and shows a consent banner so that tags only fire after consent where required.
Tracking code checklist
- List what you need to measure: page views, forms, purchases, calls.
- Install a tag manager and add tags in one place.
- Test every tag in preview mode, and check real-time reports.
- Connect a consent banner so tags respect choices.
- Document the tags, triggers and owners.
- Audit tags every quarter and remove old ones.
Tracking code mistakes
- Two copies of the same tag, which double-counts events.
- Missing tags on some pages or after a redesign.
- Many unused third-party scripts that slow the page.
- Collecting personal data without consent.
Tracking code FAQs
Do tracking codes slow my site?
Each script adds weight, so keep only what you use. See page speed and JavaScript.
What are UTM codes?
Tags added to links to record the source. See UTM tracking codes and website analytics.