How to add tracking code to a WordPress Website?

The tools and plugins recommend in the site are the ones we use, have tried or tested ourselves and recommend to our readers. Marketing With WP is supported by readers like yourself. If you take an action (such as a purchase) we might earn an affiliate revenue at no extra cost to you.

Website owners need to add tracking codes to WordPress website to implement analytics, tracking and syncing data with external services.

Below are some of the most common tools that require adding tracking code in your website:

  • Google Analytics
  • Facebook Pixels
  • Google Tag Manager
  • Marketing Automation tools
  • Google Search Console domain verification
  • Facebook Domain verification

The easiest way to implement tracking code on your WordPress website is with a WordPress plugin that allows to add tracking code to the header, body or footer area of your site.

Find out how to add tracking code to your WordPress website easily with the following step by step guide.

Why use a plugin to insert tracking code?

Convenience: It is easier and more convenient to use a plugin instead of modifying theme files.

The traditional method to add tracking code was by adding the code in core theme file (functions.php and header files). Modifying the theme file also meant the tracking code being deleted each time the theme was updated. Site owners had to add the tracking code each time core theme file was updated.

Using a plugin does not remove the tracking code each time a theme is updated.

Safe: Modifying theme files is risky and dangerous. One small error can cause the site to break. With a plugin, you can control exactly where you want your tracking code to be implemented.

With a plugin, you set it and forget it and the tracking codes stay intact even after theme file updates.

Option 1 – Use SEOPress SEO Plugin

We use SEOPress as our core SEO plugin. SEOPress has a built-in feature to add tracking code in the core plugin itself. To add your tracking code –

Step 1) Go to SEOPress Dashboard

Step 2) Go to Manage Analytics >> Tracking

Step 3) Click on Tracking

Step 4) Insert Tracking Code

Step 5) Click Save Changes

Step 6) Clear cache if you have caching enabled

Step 7) Test if tracking code is implemented by opening a new private window / incognito mode

Option 2 – Use Insert Header Footer Plugin

If your SEO plugin does not have a place to insert tracking code, you can add a header footer plugin.

You can add the tracking code easily by –

Step 1) Click Add New Plugin

Step 2) Search for “Insert Headers and Footers

Step 3) Click “Install Now”

Step 4) Click “Activate”

Step 5) Go to settings >> Insert Headers and Footers

Step 6) Insert Tracking Code in respective area (usually header)

Step 7) Click Save

Step 8) Clear cache if you have caching enabled

Step 9) Test if tracking code is implemented by opening a new private window / incognito mode

Ankit S J B Rana

Ankit S J B Rana

Ankit S J B Rana is a marketing enthusiast originally from the Himalayas of Nepal and currently based out of Bangkok, Thailand.

He is currently the Marketing Director at Mbrella Films and

Marketing With WP is Ankit's blog full of marketing insights to turn your website into a 24 hour marketing machine.

Articles: 150