Google Analytics is a powerful tool that allows you to track traffic, user behaviour, and more on your website. Although there are plugins that can assist you in integrating Google Analytics with WordPress, you might prefer to do it manually. Here’s how:

Step 1: Create a Google Analytics Account

If you haven’t done so already, you’ll first need to create a Google Analytics account.

  • Visit the Google Analytics website and create a new account.
  • Add the information about your website. After this, Google Analytics will provide you with a tracking code.

Step 2: Add the Tracking Code to WordPress

There are a few methods to add the tracking code to your WordPress site:

Option A: Add Tracking Code to Theme’s header.php File

  • Go to your WordPress admin dashboard.
  • Navigate to ‘Appearance’ > ‘Theme Editor’.
  • On the right side of the screen, you’ll find a list of theme files. Look for the ‘Theme Header’ (header.php) file and click on it to open it.
  • Paste your Google Analytics tracking code right before the closing </head> tag.
  • Click ‘Update File’.

Note: This method has a downside. If you update your theme, you’ll lose your modifications, including the Google Analytics tracking code. Using a child theme or a plugin can prevent this.

Option B: Use functions.php File or a Site-Specific Plugin

  • You can also add the Google Analytics code to your theme’s functions.php file, or even better, to a site-specific plugin. This way, you won’t lose the tracking code when updating the theme.

Step 3: Verify the Tracking Code is Working

After adding the tracking code to your website, you should verify if Google Analytics is tracking your website data:

  • Go back to your Google Analytics account.
  • Click on ‘Real-Time’, then ‘Overview’.
  • Visit your website and see if your visit is registered in the Real-Time report.


Manually adding Google Analytics to your WordPress site gives you valuable insights into your audience’s behaviour, allowing you to make informed decisions about your content and marketing strategies. While it might take a bit more effort than using a plugin, it ensures you have full control over the integration process.