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.
Get the Google Analytics tracking code
- Login to https://analytics.google.com/ with your Google account
- add an account under which you’ll be monitoring the website.
- Select the proper app type
- Enter website details
- Accept the Terms and Conditions. The next screen will be the Google Analytics account with email communications settings:
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:
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
- From the Theme Editor admin area select theme from the drop-down menu on the right part of the page
- Select the Theme Header
header.phpthe file below the drop-down theme selection on the right vertical part of the page
- Paste the tracking code in the
header.phpfile 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
- Hit the “Update” button!
That’s that, Google Analytics will now start collecting visitors’ behavior and will be accessible for data inspection.