Home > Blog > How to install Google Analytics on your WordPress

Blog

How to install Google Analytics on your WordPress

How to install Google Analytics on your WordPress

WordPress

In todays article, let's take a look at how you can easily install Google Analytics on your WordPress website!

Maintaining a website can be a very gratifying job, especially if you see it blooming over time. Of course, in order to see that, you'd need to monitor how your website is doing, and this is where Google Analytics makes its appearence.

While GA ins't the only tool around, it's certainly the most popular due to several reasons.

First of all, it's one of the ealy day tools that managed to stick around. While not the absolutely first one (for example, Analog, the first log-analyzer was created in 1996), GA is still a pioneer when it comes to monitoring and analyzing web traffic.

The platform was launched in 2005, right after Google purchased Urchin Software Corporation, which is the basis of the current web analytics.

Google Analytics in 2005

This brief history of Web Analytics will show us that a lot of other tools popped up and some made quite a progress, yet Google Analytics in undoubtly one of the most recognizable platforms.

Secondly, the fact that is part of Google's portfolio played a huge role in this, since it was widely popularized alongside other services of the technological giant, such as Google Ads (formerly known as AdWords), Google Adsense, etc.

Google have now even combined a few of its services in an entire platform called Google Marketing platform, where you can find a wide range of similar services offered by them.

Why you need Google Analytics on your WordPress

Understanding your visitors is fundamental if you want to improve the experience for them, and you want to do so in order to provide them with a reason to come back.

With over 1.5 billion live websites today, it's not hard to image that how a user can promptly go to the next site because of the tiniest detail. And while user experience for your site’s users isn’t a precise science, web abalytics can greatly help you determine what's happening on your website - where are people coming from, how they behave etc.

Some of the crucial benefits of web analytics

  • Undestand your traffic demographics: location, age, sex, interest etc.
  • Extrapolating key data related to content based on your visitor's behavior; how long they stay on a page, how many pages do they see on average,
  • Monitoring your traffic's channels and their proportions
  • Monitoring e-commerce data, including conversions, revenue, ROI (if you use Google Ads) etc.

Analytics will collect all this data from your site, then offer it in segmented section on your Google Analytics dashboard. The data in question is the basis for creating or adjusting all strategic decisions when it comes to your site, as you'll have a better idea what are you doing right/wrong.

Quick guide on How to Create a Google Analytics account

  1. Go to Google Analytics and sign in with your Google/Gmail account (if you don't have one yet, create it here)

You will be then redirected to the sign-up screen of Google Analytics.

Sign Up for Google Analytics

  1. Continue with the sign-up process by clicking on the Sign-up/Start Measuring button.

On the next screen you will see a field where you can enter the name of your accoung, and then on the next step you can choose between a website or a mobile app (or actually both).

sign up google analytics screen

Unless you have an app (or plan on developing one) you should go for Website. Once you've selected it, you can then proceed and enter your website name, your website URL, the industry category and the time zone.

Once you finish filling this information and click on the CReate button, a pop up will appear with ‘Terms and Conditions’. When you're done reading them and if you click on "Accept" you will be redirected to the Google Analytics Dashboard, with your tracking code appearing right away.

The tracking code is what's used to make the connection between your site and Google Analytics, so copypaste it somewhere (of course, you can also find it later, but since you have it already on the screen you can just get it).

You can just leave the tab open for now and copy-paste the code directly from there

You are now done with creating your Google Analytics account!

READ ALSO: How To Choose The Right WordPress Theme

How to install Google Analytics to your WordPress

You can either install it manually or via plugin. Both methods have their pros and their cons; for example, plugins are a very simple and easy way to get your Google Analytics code on your WordPress with minimal hassle. On the other hand, it's still another plugin, and if you plan on having many of them, perhaps you can try the manual method.

As always, before proceeding is best to either take a backup of your WordPress website or make sure you have one created automatically by your hosting provider.

1. Installing Google Analytics directly within the WordPress Theme:

If you have already some knowledge on working with WordPress or you aren't contrary to trying this out for yourself, you can directly insert your tracking code in your WordPress theme.

You can do so by adding the code to your header.php file or function.php file, which are accessible either via FTP or via File Manager through your hosting administration panel. If your hosting provider is using cPanel, this is where you need to go:

file manager in cpanel

If you feel uncomfortable going through FTP, you can simply use the Theme Editor directly in your WordPress. In fact, that's likely the simplest solution - you just need to follow these steps:

  1. Go to your WordPress Dashboard
  2. Click on the menu item Appearence > Theme editor

theme editor in wordpress

On the right side you will see a scrollable column where you can find both header.php and function.php.

ATTENTION: Modifying these files can damage your site, so consider the risk if you decide to go for this method!

Install Google Analytics in header.php

If you are using the Theme editor, select the theme’s header.php file from the right column and paste the analytics code right before the closing </head> tag

tracking code in header

The same is true if you're using File manager/FTP only the layout will be different, depending on what you open the header.php file with.

how to add google analytics code n wordpress header

Using function.php file:

If you want to add it to the function.php file you can proceed and open it the same way you opened the header.php then add this code at the bottom of code in the file:

add_action('wp_head','google_analytics', 20);
function google_analytics() {
?>
/* --- PASTE YOUR GOOGLE ANALYTICS CODE HERE -- */
<?php
}

2. Install Google Analytics via WordPress plugin

if you don't want to risk it or you don't feel comfortable manually editing your code, there is a very simple solution - do it via plugin. Using a plugin can add a bit to your resource consumption, but it could also prevent damagin your WordPress site, as PHP edits can be dangerous for people without tech skills

Right now there is a wide rande of plugins that will help you inslal your Google Analytics, so all you need to do is choose one. While they serve the same purpose, there can be some differences between them, so let's take a look at what some of the most popular Google Analytics plugins can offer you.

Keep in mind that when you install Google Analytics via WordPress plugin, it usually doesn't require your entire tracking code, but something called UID which looks like this UA-1345545554. This User ID can be extrapolated directly from the tracking code.

Google Site Kit

The plugin Site Kit is actually the official WordPress plugin from Google. It was created by Google in order to facilitate WordPress site owners installing their products.

Site Kit is developed rather well, with its main advantage being that you can use it to connect to several of Google's services: - Google Analytics - Google Search Console - Google Adsence - Google Pagespeed - Google Tag Manager - Google Optimize

Once you've installed it, there is a guided setup process:

google site kit wordpress plugin

You'll need to use your Google account in order to proceed here.

Google Analytics Dashboard for WP

Possibly the most popular free WordPress plugin for Analytics, this one has over 1 million active installation to this date.

One of its particularities is the very in-depth stats and reports available directly trough the WordPress dashboard (meaning, you won't have to go to the Google Analytics Dashboard in order see them).These stats will allow you detailed segmentation of your analytics data, providing an amazing quantity of information for each post or page.

It's also worth noting that the plugin can be used on multisite as well, and it fully compatible with the AMP framework.

GA Google Analytics

This simple, yet popular plugin has been developed “with love for the WordPress community” according to its creator. GA Google Analytics has been designed to do exactly what you need with minimal distractions.

Its simplicity allows a very fast performance, making it one of the top choices if you don't want something too heavy on your site. Unlike the previous entry, data cannot be viewed directly in WP, so keep this in mind, if it's an important thing for you.

The plugin has a premium version as well, which offers the customers an easy opt-our and advance features such as:

  • Universal Analytics (default tracking method)
  • Global Site Tag (new tracking method)
  • Legacy Tracking (deprecated)
  • Display Advertising
  • Enhanced Link Attribution
  • IP Anonymization and Force SSL
  • Custom Tracker Objects and more!

Google Analyticator

Google Analyticator is another very popular Google Analytics WordPress plugin. Analyticator was purchased by SumoMe and has been in their portfolio for a while now.

The plugin is designed to display your Google Analytics data directly on your WP dashboard, and has other additional features. The main thing that distinguishes it from the other plugins is its ease of use; you don't even have to know your Google UID - all you need to do is sign in with your Google account.

google analyticator

Final thoghts on Google Analytics

Clearly, not monitoring and analyzing your website's traffic today isn't an option. Choosing Google Analytics for your WordPress can help you determine in a very efficient manner everything you need to know about what's going on when it comes to your website.

Google Analytics and WordPress has been a powerful combination for years, so don't hesitate to try it out and reap all the benefits it will offer!

Back to top