How to setup Google Analytics on a WordPress site


In order to use the visitor’s experience and learn from the visitor’s behavior on your website, you need to know how to set up Google Analytics. This article covers the setup process of Google Analytics on a WordPress website. 

Specification:

WordPress Version: 5.4.2

Get the Google Analytics tracking code

Google Analytics on a WordPress | Create Account
Google Analytics | Create Account
  • Select the proper app type
Google Analytics on a WordPress | Create Account - app type
Google Analytics | Create Account – app type
  • Enter website details
Google Analytics on a WordPress | Website details
Google Analytics | Website details
  • Accept the Terms and Conditions. The next screen will be the Google Analytics account with email communications settings:
Google Analytics on a WordPress | Email communication
Google Analytics | Email communication

Now after the account is all set up we should go and grab the tracking code. Usually, after the first time you’ve set up the account as displayed in the above process the tracking code will be shown immediately.

Tracking code can be found under the Admin menu -> Tracking info -> Tracking code:

Google Analytics on a WordPress | Tracking Code
Google Analytics | Tracking Code

Use the Google Analytics tracking code in the WordPress site

The point of the tracking code is to be loaded with each page of the site and thus, track the behavior of the visitor. With WordPress, we are using one specific theme file that is loaded as part of each post or page, “header.php”.

  • Login to the WordPress admin area
  • Navigate to Appearance – Theme Editor
Google Analytics on a WordPress | Theme Editor
WordPress | Theme Editor
  • From the Theme Editor admin area select theme from the drop-down menu on the right part of the page
Google Analytics on a WordPress | Theme Editor
WordPress | Theme Editor
  • Select the Theme Header header.php the file below the drop-down theme selection on the right vertical part of the page
  • Paste the tracking code in the header.php file within the <head></head> tags. For the sake of easier organization, let’s place it at the very end of <head> section – right above the closing </head> tag.
Google Analytics on a WordPress | Theme Editor | header.php
WordPress | Theme Editor | header.php
  • Hit the “Update” button!

That’s that, Google Analytics will now start collecting visitors’ behavior and will be accessible for data inspection.

Google Analytics on a WordPress | Google Analytics Dashboard
Google Analytics Dashboard
Share this post

Share this link via

Or copy link