Home » Digital Marketing Blog » How to Add Google Analytics to WordPress Site?

How to Add Google Analytics to WordPress Site?

Google Analytics is one of the most important tools for analyzing your website, from the entrance of users in your site to exit, and all what they have done on your site.

WordPress is a most popular content management system in the world, so if you use this system and have not added to Google Analytics, this article for you. If you’re using another content management system, we will take care of you in our other guides.

What do you need to add the Google Analytics WordPress site?

  1. Google Analytics account.
  2. A website for WordPress on your own server (not wordpress.com).

Google Analytics Account

If you do not have a Google Analytics account, you can register for free on the site: analytics.google.com, if you have a Google account, you can sign up with it, otherwise, you’ll have to create a new user on Google. You must set your site or landing page in Google Analytics, it is not difficult, we expand another article.

You must copy the embed code. You can do this by clicking on “Admin”> “tracking info”> “tracking code”. In this section, you will see your Tracking ID and the tracking code. Here is an example of the code. This code to implement your WordPress site: Tracking ID or Tracking Code.

Recommended tools for WordPress sites
  • Cloudways - Best WordPress web hosting!
  • Elementor PRO - a WordPress page building plugin (recommended).
  • JetPlugins - an extension plugin for Elementor (recommended).
  • Astra PRO - a WordPress theme among the best.

WordPress Website on your own server

You must hold admin user on your WordPress site and embed the code above in the following ways:

  • Add tracking code by editing the site code.
  • Add tracking code by adding the template/theme.
  • Add tracking code by an extension (plug-in).

Editing site code

You can add the Google Analytics by code editing with your site. The biggest advantage that you do not have to install a plugin specifically for Google Analytics. There are two major disadvantages, the first is that you should edit your website code so you must be careful not to do harm, the second when the theme is updated maybe that after the update, the code will be erased and will not follow to the new version.

To add the code, the control panel of a WordPress site, go to “Appearance” and then click “Editor”. Now You will have several options to add:

  • header.php – This is the top of the page, click on header.php, add the tracking code and paste it above the </head>.
  • footer.php – the end of the page, click on footer.php, copy the code and paste it tracking over the </body>.
  • Functions.php – more advanced, with the help of PHP applications. This is sensitive, so be very careful (we will not elaborate it here).

Add the template/theme

If you have a theme/template with its own settings such as Divi by Elegant Themes, you can add the Google Analytics code directly into the template without the need to edit the code of the site. These two outstanding benefits of it, you do not need to install a plugin specifically for implementation of the code, and you do not need to edit the code of the site.

Extension / plugin

Another option is installing a plugin on plugins directory on WordPress.org site. You can also click the “Plugins”> “Add new”> Search “Google Analytics” in the search box.

Adding Google Analytics to WordPress site was successful, now where you copied the Google code, you can see if there are users on the site and also check if the code is implemented correctly.