How to add tracking code to a WordPress Website?

The tools and plugins recommend in the site are the ones we use, have tried ourselves and recommend our readers. Marketing With WP is supported by readers like yourself. If you take an action (such as a purchase) after clicking on our affiliate links, we may earn some coffee money to create more helpful articles. As always, we thank you for your support.

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 is the founder of Marketing With WP and wants to help those who want to pursue a career in digital marketing.

From Co-Founding a successful boutique travel brand, Nepal101 to setting up Mbrella Films, Southeast Asia's #1 Film Production Company, online leads funnel to generate hundreds of B2B leads, he has done it all.

With Marketing With WP, Ankit wants to help marketers like yourselves utilize WordPress and other online tools to turn your website into a 24 hour marketing machine.

Articles: 85