How to Add Google Analytics to WordPress

How to add Facebook Like button to WordPress
3 Benefits of Website Hosting in Conversion Optimization for Your Website

If you want to have a successful site, it is essential to know your audience and what they expect from their website. The best way to achieve this is by analyzing your traffic. That’s exactly what Google Analytics does. This Google’s free software allows you to track visitors to your site, analyze their habits, traffic sources, social metrics and different statistics and more. Analyzing statistics, you can plan and create better content for your readers. This tutorial will show you how to sign up and add Google Analytics to your site WordPress .

Why do you need Google Analytics on WordPress?

Things are very easy when you know what your users want from you, your site and its services, are not they? The only way to make your visitors spend time on your site and come back again is by providing what they need. That’s exactly what Google Analytics is free! Here are some reasons why we suggest you to add Google Analytics to WordPress and see why each WordPress blog must have it:

  1. It helps you to determine the behavior of its users . Yes, you can track just about the behavior of your visitors with Google Analytics. You can easily check the most viewed pages, the average time each user spent on a particular page, the pages with the best performance, as well as detect the page that makes visitors want to leave your site and more. It is vital that we can say that having a quick look at this information would help you better optimization of your website. If a certain blog post are driving the most views, you could write more posts on related topics and attract more traffic.
  2. It helps in the analysis of the most active time . You can easily determine the time you get more traffic. If most users are active at night, it is obvious that in order to capture more views, you should schedule your posts to be published in this slot.
  3. It helps you explore the crucial details . Google Analytics can provide the smallest details – from the geographical location of any user in the language they speak, the browser you use, the screen resolution and the likes. Thus, it helps you better understand your audience.

Although there are some other web analytics services that you can use, Google Analytics provides a variety of unique features. Let’s take a quick look at each of them:

  1. Generate custom reports easily . The best way to analyze the behavior of its users is by using facts and figures. This could be done easily generate custom reports with an easy to understand interface. You can add multiple parameters and metrics to generate an insightful report.
  2. Set up custom alerts . This is a truly amazing part of Google Analytics with which you can send custom alerts in the form of a text message or an e-mail every time there is a sudden dip in traffic or a drastic change in bounce rate. So, you no longer need to keep your eyes glued to your dashboard to capture important updates.
  3. Integrating Search Console . Keep a sharp eye on statistics related to SEO and figures is important. Search Console is one such tool that provides information related to the optimization of search engines. Integrating Search Console with Google Analytics would make the information easily accessible under one roof for rapid analysis.

These are just some of the many features of Google Analytics that make the whole process of handling a WordPress site easily!

How does Google Analytics work?

You may already think that Google Analytics is amazing. But how does it do this? Well, we understand that having a basic knowledge of how the software works helps you make the most out of it. Broadly speaking, Google Analytics is:

  1. Code JavaScript  When a user falls on your site, the JavaScript code runs to collect all the important information about the site itself, the information about the visitor, such as the browser used to find your site, operating system, screen resolution and so on.
  2. Data collection service  Once all this information is collected by the JavaScript code, is sent to Google ‘s servers for processing in the form of small packages called hits. These hits are sent whenever a visitor opens your site.
  3. Data processing  During data processing, Google Analytics servers turn raw data into useful information. For example, categorize your visitors based on their location, language, screen resolution, device type , and so on.

That’s how it works. It may seem an easy process at first, but a lot of features and processing is going on behind the scene.

We hope that this certainly reinforced the decision to add Google Analytics to your WordPress site. No more beating around the bush, here’s a quick tutorial that will show you how to sign up and add Google Analytics to your site WordPress .

What do you need?

Before beginning this guide, you need the following:

  • Access to WordPress control panel

Step 1 – Creating a Google Analytics Account

The first thing you need to do is create a Google Analytics account and get the tracking code. The steps below show how to sign up for Google Analytics:

  1. Start by navigating to the home page Google Analytics . Press Enter , which is located at the top of the page and select Google Analytics .
  2. You will be redirected to the login page. Enter your Google email address and press the button Next . If you do not already have a Google account, create one by pressing the Create Account .
    google analytics sign up
  3. On the next page, enter your password and press the Enter .
    google analytics sign up 2
  4. Press Subscribe  to proceedgoogle analytics sign up 3
  5. To create a new account, you must enter the following information:
  1. Account name.
  2. Website name.
  3. Website URL.
  4. Industry category.
  5. Time Reporting Time .

google analytics new account page

Fill in all required details and press the button Get Tracking ID  ( 6 ). On the next page, you will be prompted to accept the Terms of Service, then click on Accept .

That’s it! You created a Google Analytics account successfully. On the next page, you will see the universal tracking code Google Analytics:

<Script>
(Function (i, s, a, g, r, a, m) {i [ 'GoogleAnalyticsObject'] = r; i [r] = i [r] || function () {
(I [r] .q i = [r] .q || []) push (arguments)} i [r] .l * 1 = new Date ();. A = s.createElement (o)
s.getElementsByTagName = m (o) [0]; a.async = 1; g = a.src; m.parentNode.insertBefore (a, m)
}) (Window, document, 'script', 'https: //www.google-analytics.com/analytics.js','ga');

ga ( 'create', 'UA-00000000-1', 'self');
ga ( 'send', 'pageview');

</ Script>

This JavaScript code is identical for all sites. Only the tracking ID ( UA-00000000-1 ) is unique. You should see your on the same page. The tracking ID begins with UA , which means Universal Analytics, the first set of numbers is the account number ( 00000000 ) and the last number is the Google Analytics ID ( 1 ).

Step 2 – Adding Google Analytics to a WordPress blog

There is more than one way to add the Google Analytics tracking code to WordPress: Using a Plugin, adding the tracking script directly to the file header.php  or creating something new in the file functions.php .

Option 1 – Using a Plugin

If you are not familiar with the structure of WordPress and PHP files, it is recommended to use the Plugin method. One of the best plugins for this is Google Analytics Code Integration . This plugin will automatically insert the tracking code for Universal Analytics – you only need to enter your tracking ID.

The steps below show how to install the plugin and insert your Google Analytics tracking ID:

  1. Sign in WordPress Dashboard and install the plug-in Google Analytics . Follow this tutorial  if you are unsure about how to install new plugins in WordPress.
  2. When the installation is complete, navigate to the Settings  and press the Google Analytics code .
  3. Paste the code in the field and click Save .

google analytics add to wordpress

4. That is, the tracking code has been successfully added to your WordPress blog.

Note that it may take 12-24 hours for the Google Analytics upgrade and begin to show the first results. Later, statistics on your target audience will be provided on the tab Reports  Analytics.

google analytics report section

Option 2 – Entering code in header.php

As we said, there are some ways to insert the Google Analytics code into a WordPress blog. For example, the code can be included in the file header.php  of your theme:

  1. Go to WordPress admin area and navigate to Appearance -> Editor .
  2. Open header.php  for editing.
  3. Enter the Google Analytics tracking code acquired in Step 1 before the closing tag </ head> and press the Reload file .

google analytics tracking code added to header php

Note: Google Analytics code is inserted only on your active theme. You will need to add it back if you change the subject.

Option 3 – Creating a new function in functions.php

This method requires some basic knowledge of coding and we recommend that you follow only when you are confident in what you ‘re doing. Moreover, it is highly recommended to create a backup file functions.php  or even the entire WordPress installation before continuing:

  1. While in the WordPress dashboard, navigate to the Appearance -> Editor .
  2. Select functions.php  in the file list on the right.
  3. The following code snippet creates a new function and insert the Analytics tracking code immediately before the closing tag </ head> in your WordPress site. Paste this code at the bottom of the file functions.php , but do not forget to change your tracking ID.

    add_action ( 'wp_head' 'my_analytics', 20); my_analytics function () {
    ?>
    <Script>
    (Function (i, s, a, g, r, a, m) {i [ 'GoogleAnalyticsObject'] = r; i [r] = i [r] || function () {
    (I [r] .q i = [r] .q || []) push (arguments)} i [r] .l * 1 = new Date ();. A = s.createElement (o)
    s.getElementsByTagName = m (o) [0]; a.async = 1; g = a.src; m.parentNode.insertBefore (a, m)
    }) (Window, document, 'script', 'https: //www.google-analytics.com/analytics.js','ga');
    ga ( 'create', 'UA-00000000-1', 'self');
    ga ( 'send', 'pageview');
    
    </ Script>
    
    <? Php
    }

     

  4.  Save your changes by clicking the Update File .

google analytics functions added to php

Note: The code will be inserted only in your active theme. If you change your theme, you will have to re-add the code again.

Conclusion

Needless to say how much Google Analytics is essential to your WordPress site in order to better understand your audience. After completing this tutorial, you learned how to create a Google Analytics account and three different ways to add Google Analytics to your WordPress blog. Check out our tutorials to stay on top of all matters relating to the world of technology and hosting sites .