How to install google analytics in wordpress

Using Google Analytics for WordPress helps you to understand how visitors interact with your site and content. Google Analytics is a free web analytics service that allows you to track traffic, behaviour, and more conversions on your site.

In this post, you will learn how to set up Google Analytics in the dashboard of WordPress. Besides, you will have some introductory techniques for measuring precious traffic data.

10 Must Have WordPress Plugins

Google Analytics Feature

  • Real-time: Shows what is happening on your site at a specific time that you look at the report.
  • Behavior: Indicates what visitors do on your site, including clicks buttons and your pages are most popular.
  • Conversions: An advanced report for use in conjunction with Google Analytics goals, to track activity such as the list of e-mail subscriptions or sales e-commerce.
  • Audience: Includes information about people who visit your site, including demographic data.
  • Acquisition: Explain how your site gains traffic.

Why Google Analytics important

  • Who visits your website – Analytics helps you to analysis the browser using the user to visit your website and screen resolution.
  • Where they come from – Analytics Answers What is the geographic location of your audience.
  • What they do on your website once they are there – You can track where users go to your site, how long they stay on your site.
  • When do people visit your website – You can analysis users visit hours of the day to your site, you can choose when you publish your posts.
  • How do people find your website – This section of the analysis shows you where people have come from (eg. search engines, direct links, reference links from another site).
  • The success of your content – Analytics shows how your users interact with your content. It shows you what percent of the user clicked that link to your website and more.
  • And much more.

How to Add Google Analytics to WordPress

1. Create Google Analytics Account

You must configure your Google Analytics (GA). Click this link where you can connect to an existing Google account or create a new one.

If you already have a Google Analytics account, then go to the next section. Otherwise, follow these steps:

Go to Google Analytics Sign Up page and use your Gmail account to Sign Up.

  • Now, you will be taken to the account setup screen.
signup
  • You are asked to enter data in the required fields such as’ name of your account will Google if you don’t have google account.
  • Adds profile name analysis for your website. You can use whatever name you like.
  • Make sure you click on the ‘Web’ option if you want to track your website. However, the option for ‘Mobile App’ is also there.
web
  • You can keep track multiple websites from a single account.
  • Now, you will see a popup window displaying Terms of Service Agreement, click ‘I Agree’ to continue.
agrement

You have successfully signed up for Google Analytics.

How to Start Blog?

2. Install Google Analytics(GA) in WordPress

By using plugins

If you do not want to mess with the theme, you can use third-party plugins to do the work for you. Not only is it easy, but it reduces the risk of messing up the code. There are tons of plugins to choose from and I discussed here MonsterInsights.

It is one of the Google Analytics plugin the most reliable and widely used by over 2 million active installs. The basic version of MonsterInsights free and it includes features that are quite good. But if you want more, you can go for the Pro version that comes with a money-back guarantee 14-day and starting price of $99.50 per year

Here’s how to add Google Analytics to MonsterInsights:

  • From your WordPress dashboard, navigate to Plugins -> Add New.
  • Searching Google Analytics Dashboard Plugin for WordPress by MonsterInsights Plugin. Download and activate it.
  • Return to your WordPress dashboard. A selection of new insights should pop up.
misetup
  • Scroll down a bit and you will see the Launch Wizard! button. Click on it. Follow the instructions to complete your initial setup. This is where you have to MonsterInsights connect to your Google Analytics account.

signinga
  • Continue to follow the instructions and fill out the required information. Once everything is complete, you will see the Finish Setup & Exit Wizard button.
  • Congratulations, you’ve completed the integration process! You can go to the Insight -> Report to view the performance of your site.
gareports

Manually connect GA and WordPress/any website with code

Once you have completed the registration process, the service will take you to an area where you can get the code for Google Analytics. However, if you want to retrace the steps, here’s how to get the tracking code by hand:

GA analytics
  • Sign in to your Google Analytics account, then navigate to the Admin menu in the bottom left.
  • Click on the menu Tracking Info. Then, click on the sub-menu Tracking Code.
  • You should now be able to see your ID and Global Site Tracking Tag. Save this code as we will need it later.
  • Google Analytics Tracking Code page that will be used to add Google Analytics to your WordPress site or any other site as well
  • Once you obtain the tracking code, you can navigate to your WordPress to begin the configuration steps.

1. functions.php Code

There are several ways to add Google Analytics for WordPress using code snippets.

The first location where you can add the Google Analytics tracking code in functions.php file. You create a new function that contains the code snippet.

  • In your WordPress dashboard, navigate to the Scene Editor section under the Appearance menu.
  • Open Theme Functions (functions.php) file of the right column.
  • Add the following code snippet to the file. Remember to replace with your tracking ID.
  • Once you are done, click on the Update button File to save the changes.
Functions php file
<?php
function wpbtech_add_googleanalytics() { ?>
 
// Paste your Google Analytics tracking code from Step 4 here
 
<?php } ?>
add_action('wp_head', 'wpbtech_add_googleanalytics');

2. Code header.php

You can also add Google Analytics tracking code for the Theme Header (header.php) file.

  • Navigate to Theme Editor once again.
  • Scene Open Header (header.php) file in the right column.
  • Paste the code snippet in the header or, more specifically, in the above </ head> tag.
mannul ga code 1
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-26575989-48"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-1234567-48');
</script>
  • Once you are done, click on the Update button File to save the changes.

Final Word

If you ask which method is good for wordpress site. I will select the manual one because it doesn’t consume any memory and keep your website lightweight

But if you don’t want to mesh with code go with the plugin.

Related