How to install Google Analytics in WordPress

Do you want to install Google Analytics in WordPress? These stats will help you to find out important information about your visitors.

How to install Google Analytics in WordPress

What is Google Analytics?

Google Analytics (GA) is a web-based tool for anyone who needs to collect and analyze visitor information for their website. Thanks to GA, you’ll find out who visits your site, where visitors came from, whether they bought something from you, or what they did on your site.

The information collected will tell you more about the geographic location of the visitors, how they use the browser, the screen resolution, and many other useful information.

What can be tracked?

GA records many important data. Worth mentioning include:

  • who visited your website
  • what is your audience’s geographic location
  • what browser was used
  • what was the browser language
  • what was the screen resolution
  • whether it was a mobile or desktop
  • what visitors do on your website
  • when you have the most visitors
  • where visitors came to your site from

What can this information be used for?

Thanks to its versatility, Google Analytics is used by sites of various focus from e-commerce and bloggers to online newspapers and magazines. This tool provides important information for optimizing your site or ad campaign.

Thanks to the fact that you know the behaviour of your customers on the site, you can distinguish your target audience from all internet visitors. You will better understand what content they are interested in and what shopping or other expectations they have.

It helps when adjusting design

The data collected is important for suggestions for editing a website’s design or customizing it to make it more convenient for site visitors. For example, if you find that most of your users are not using Flash support, you will know that you should not add content that uses this plugin to your site.

It helps to improve content

With information about site visitors, you’ll find out what people are really interested in. This will help you add new articles. Thus, you will reduce the number of page exits and increase the number of its views.

You will find out when it is best to add new content

GA collects traffic data throughout the day. You’ll find out when the site’s traffic is greatest. You can then plan to add new content right at this time.

Linkbuilding

The collected data also includes information about how people found your site. Whether through search engines, social networks or direct links. This will help you create new links to your site from other websites.

💡 Tip: Choosing the right hosting is crucial for a fast website ⏱ . I recommend betting on verified quality ➡️ Bluehost or SiteGround.

How to register to Google Analytics

GA registration is available to everyone for free. You only need a Google Account or Gmail to use it. Registration is done in a few simple steps.

1. Sign in to your account

First, go to Google Analytics via this link. Sign in to your Google Account here. If you don’t already have a Google Account, you’ll need to create one first:

Ako sa prihlásiť do služby Google Analytics
How to sign up for GA

2. Sign up for Google Analytics

When you sign in, you’ll be taken to the following page where you learn how the entire process will look like:

Registrácia do služby Google Analytics
Sign up for GA

Click Sign Up to continue.

3. Enter your details

In front of you, there is a page where you need to fill in your details. First, choose the Website Name option.

Next, enter the account name. This means that you enter the GA profile name for your website or multiple pages you want to track. Then, fill in other information like the website name, its URL, industry, country and time zone.

Finally, click Get Tracking Identifier. You can find it at the bottom of the page.

Pridanie webstránky do GA
Adding a website to GA

To complete, you’ll be prompted to agree to the Google Analytics Terms and Conditions.

4. Tracking code

On the page in the picture, copy your tracking code. You will need to enter it on your WordPress site.

Získanie kódu sledovania
Obtaining GA tracking code

Keep the page with code open for now, so you have the code at hand. If you close the page and need your code later, you will get it by logging into your Google Account. Go to User Management -> Tracking Info -> Tracking Code.

💡 Tip for themes: From premium themes, I have good experience with themes Divi, Avada and with page builder Elementor.

Installing Google Analytics via MonsterInsights Plugin

You can purchase MonsterInsights as a premium plugin or in free version. The premium version is enhanced with some features like ad tracking, sub-page tracking by author, or tracking popular posts and sites.

Google Analytics Dashboard Plugin for WordPress by MonsterInsights

Next, I’ll show you how to install Google Analytics through the free version of MonsterInsights, which you can find on the WordPress repository under the name Google Analytics Dashboard Plugin for WordPress by MonsterInsights.

Here are a few steps to follow:

1. Install MonsterInsights Plugin

First of all, install MonsterInsights plugin. You will install this new plugin by logging into the page administration under Plugins ›Add new. After activating the plugin, you will be redirected to the page as you can see in the following image. At the same time, a new Insights entry is created in the page menu.

Inštalácia pluginu MonsterInsights
Installation of MonsterInsights plugin

On this page, you select the category of your website. Click Save and Continue..

On the next page, click Connect MonsterInsights.

2. Google Account Setup

Now you can see the page with Google accounts. You’ll need to sign in or, if you’re already signed in, choose a Google account.

The next step is to enable MonsterInsights plugin to access to your GA account. Click Allow to enable.

Now you select the profile you want to track. Choose your website and click Complete Connection.

3. Site settings

After you install the plugin on your site, you’ll choose the recommended settings for the page. For most sites, keeping the default settings is the best choice. However, if you’re using an affiliate plugin, add link tracking. Click Save and Continue to save your settings.

If you want to switch to a paid version of MonsterInsights, you can do so on the next page. To use the free version, simply click on Save and Continue to skip this step.

4. Installation of WPForms (optional)

You have now reached a page where you can choose to install the WPForms plugin that is used to create contact forms. If you don’t want to use it, you can skip this step.

Now you have MonsterInsights installed successfully. In some time, you will have the first page tracking results available. Click Finish Setup & Exit Wizard to complete.

Displaying GA Reports

You will have GA reports available whenever you visit your site. Just go to its administration. You can find your reports under Insights.

Zobrazovanie štatistík (dashboard)
Zobrazovanie štatistík (dashboard)
💡 Do you want a faster ⏱ website? Website speed is important for both visitors and SEO. I got the best results thanks to the WP Rocket plugin, which I highly recommend.

Adding Google Analytics via the Headers and FootersViewing statistics Plugin

To track Google Analytics reports, you can also use the Insert Headers and Footers plugin. In addition to embedding Google Analytics, this plugin also allows you to include custom CSS or other codes in the WordPress header and footer.

First, install Headers and Footers plugin. After installing and activating the plugin, you will insert the Google Analytics code on the administration page of Settings »Insert Headers and Footers.

Plugin Insert Headers and Footers
Insert Headers and Footers plugin

Installation of GA without using pluginu

Adding code to header.php

One way you can use is to paste the code into the header.php file. This is only recommended if you can work with page codes.

If you paste the tracking code into the header, it will load on each page. When using the child theme, remember that these changes need to be made in the child theme, so that you don’t lose them when updating the page.

You paste the Google Analytics code you copied into the header.php file after <body>. Save your changes on the server.

Adding code through a set of features

You can also add Google Analytics code to the function.php of the theme. This will add the code to each subpage of the site.

function vj_google_analytics() { ?>
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-11111111-1">
</script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'UA-11111111-1');
  </script>
  <?php
  }
  
add_action( 'wp_head', 'vj_google_analytics', 10 );

If you have an e-commerce, read this Tutorial on how to install Google Analytics in WooCommerce.

Was this article helpful for you? Support me by sharing, please. 👍
WordPress Návod v PDF

LEAVE A REPLY

Please enter your comment!
Please enter your name here