将Google Analytics统计代码添加到WordPress的多方法插图

Many WordPress users have difficulty connecting Google Analytics to their WordPress site, and they miss the opportunity to collect user data.

Fortunately, there are several ways to add Google Analytics to WordPress. Once you know what you’re doing, these techniques are fairly simple and can prove useful in a variety of situations.

In this article, we will discuss the role of Google Analytics and its importance to your site. Then we’ll share four ways to connect it to WordPress to start tracking activity.

  1. Google Analytics introduction
  2. Why analysis is important to your WordPress site
  3. How to add Google Analytics to WordPress

Google Analytics introduction

Before you start connecting Google Analytics to your WordPress site, it’s best to know what it is and how it works. In short, the platform monitors your site’s activities and provides you with key data to help you improve it:

将Google Analytics统计代码添加到WordPress的多方法插图1

Google Analytics home page

By using code snippets that insert the title of each page on your site, Google Analytics collects a variety of information, which can be divided into five categories:

  • Real-time: shows what happens on your site at a specific time when you view the report.
  • Audience: includes information about who is visiting your website, including demographic data.
  • Get: explain how your site gets traffic.
  • Behavior: show what visitors do on your site, including button clicks and which of your pages are the most popular.
  • Conversion: advanced reports used in conjunction with Google Analytics goals to track activities such as email list subscriptions or e-commerce sales.

Examples of specific information that you may find in the Google Analytics report include:

  • The number of active users on your site at any given time.
  • How many people visit your website over time.
  • The age, sex and location of the visitor.
  • Where your visitors come from (for example, natural search, social media, etc.).
  • Which pages have visitors viewed and how long they have been viewing them.
  • Bounce rate, click rate and conversion rate.

You can view and learn a lot in the Google Analytics dashboard. This can help you improve your website in a variety of ways.

Why analysis is important to your WordPress site

If you know how to make the most of them, analysis is valuable to many different aspects of your site. Four key areas related to any type of website include:

  • Content marketing strategy. By considering your most popular posts, pages, products, or other content, you can determine what visitors like best. Increasing page views and traffic is a matter of creating more types of content that resonate best with your audience (here is how to start keyword research and how to optimize WordPress for SEO).
  • Inbound marketing. Knowing where your traffic is coming from can tell you which marketing strategies are effective and which are declining. You can then focus most of your energy and budget on the method that produces the most results.
  • Audience segmentation. Knowing your audience is the key to effectively communicating with them to encourage transformation. Through analysis, you can create subgroups for targeted marketing.
  • User experience (UX) audit. User behavior flows can reveal problems with your navigation or website design. Identifying underperforming content and pages with high bounce rates may help you improve the problem area.

If you run an e-commerce site, the conversion report can also help track sales and revenue.

As you can see, it’s not always the numbers that matter. How to apply the knowledge gained from Google Analytics is the value. Solving problem points and applying the best marketing techniques to your site can increase traffic, conversion rates, and revenue.

How to add Google Analytics to WordPress (4 possible ways)

If you are trying to collect data about your users, you can connect Google Analytics to your WordPress site in the following different ways.

In each case, we assume that you have set up an Google Analytics account. If you don’t, create one first, and then come back to the next step.

  1. Use the Google Analytics WordPress plug-in
  2. Manually connect Google Analytics and WordPress using code
  3. Integrate Google Analytics and WordPress with Google Tag Manager
  4. Synchronize Google Analytics locally for performance reasons

1. Use the Google Analytics WordPress plug-in

The easiest way for most WordPress users to add Google Analytics to their site is to use the Google Analytics WordPress plug-in. This method eliminates the need to edit the code for the site.

To do this, we recommend three plug-ins:

Install Google Analytics using Site Kit by Google

If you want to add Google Analytics to your WordPress site, Google provides you with a simple but powerful plug-in: Site Kit by Google.

将Google Analytics统计代码添加到WordPress的多方法插图2

Site Kit by Google plug-in

This free plug-in connects Google Analytics to your WordPress site with just a few clicks, but that’s not all. In addition to analysis, this plug-in also extracts data from other services provided by Google, such as Google Search Console, Google AdSense, and PageSpeed Insights, allowing you to build a beautiful dashboard based on Google as a data source.

Here’s how to get started:

Install and activate the Site Kit by Google plug-in, and then click the Start Setup button.

将Google Analytics统计代码添加到WordPress的多方法插图3

Set up the WordPress plug-in Google Site Kit

When you are done, you need to connect the WordPress website to your Analytics account.

As you might expect, you need to perform several steps to verify that you are the owner of the domain, grant Google access to its data, and set up each service you want to add to WordPress.

将Google Analytics统计代码添加到WordPress的多方法插图4

Google Site Kit set successfully

After successfully connecting to your Google account, you will be able to view data from Google Analytics and all other services that are activated directly in your WordPress dashboard. This is what it looks like:

将Google Analytics统计代码添加到WordPress的多方法插图5

Google Site Kit Information Center

All of this data will always be accessible directly in WordPress in the left sidebar.

If this plugin is too much for you and you want to focus on Google Analytics, you can use the next plugin.

Install Google Analytics using GA Google Analytics

Jeff Starr’s free GA Google Analytics plugin has more than 400000 active installations and five-star ratings:

将Google Analytics统计代码添加到WordPress的多方法插图6

WordPress plug-in-GA Google Analytics

After installing and activating the Google Analytics WordPress plug-in, you only need to add your Google Analytics tracking ID to its settings. To retrieve your tracking ID, go to your Google Analytics account and click Admin in the sidebar:

将Google Analytics统计代码添加到WordPress的多方法插图7

Google Analytics (Analytics) Management label

Under Property, select Tracking Info, and then click Tracking Code:

将Google Analytics统计代码添加到WordPress的多方法插图8

Access Google Analytics tracking code under attribute information

Your trace ID will begin with UA and will be at the top of this section:

将Google Analytics统计代码添加到WordPress的多方法插图9

Visit Google Analytics to track ID

In your WordPress dashboard, navigate to Settings & gt; Google Analytics. Scroll down to Plugin Settings and add your tracking code in the relevant fields:

将Google Analytics统计代码添加到WordPress的多方法插图10

GA Google Analytics WordPress plug-in Settings Page

The plug-in also allows you to choose whether to place trace code in headers and footers, add custom tracking code, force SSL, disable tracing for administrator users, and other useful options.

After adjusting to your needs, scroll down and click the Save changes button. Google Analytics should now be active on your WordPress site.

Install Google Analytics using MonsterInsights

MonsterInsights offers a variety of different solutions according to your needs. Sign up for MonsterInsights, choose the solution that suits you (paid), and then download the plug-in. If you’re just getting started and don’t need too much functionality, you can also use MonsterInsights Lite (the free version) to start using MonsterInsights. To do this, go to the plug-in on the right side of the WordPress dashboard, and then go to install the plug-in (Add New). Search for MonsterInsights in the search bar to find the corresponding plug-in, click install now (Install Now), and then click Active.

将Google Analytics统计代码添加到WordPress的多方法插图11

After downloading and activating the plug-in, clickInsights“and then click”Settings (setup)“by clicking”Authenticate with your Google account (Use the Google account for authentication) button to authenticate Google Analytics on your website.

将Google Analytics统计代码添加到WordPress的多方法插图12

You will then be prompted to chose/sign (select / log in) your Google account again. After you select a Google account, a window pops up asking for permissions for the MonsterInsights administrative account. Click Accept.

将Google Analytics统计代码添加到WordPress的多方法插图13

Finally, all you have to do is select your website and click Complete Authentication.

将Google Analytics统计代码添加到WordPress的多方法插图14

Now, you can click “Insights“and then click”ReportsEasily view reports on site traffic and analytics from the WordPress dashboard. All the reports look great and are very easy to understand.

将Google Analytics统计代码添加到WordPress的多方法插图15

two。 Manually connect Google Analytics and WordPress using code

If you don’t want to use plug-ins, it’s pretty easy to add Google Analytics tracking code directly to your WordPress theme through your functions.php file.

If you do it manually, you must use subtopics so that your tracking code is not overwritten each time the WordPress theme is updated. However, it is best to make a backup before making any changes.

Once your subtheme is active, you need to end it in the header.php filePaste your Google Analytics tracking code before the tag.

To find your Google Analytics tracking code, go to your account and access your tracking information, as we described in the previous method. You can then copy the script from the box under Google Site Tag:

将Google Analytics统计代码添加到WordPress的多方法插图16

Copy the Google Site Tag code

To add it to your WordPress site, go to the appearance & gt; theme file editor. If your child theme inherits the template file from its parent theme, you will not see header.php here. You can access it by clicking the name of the parent topic in the file list:

将Google Analytics统计代码添加到WordPress的多方法插图17

WordPress theme Editor for subtopics

After you find and select header.php, paste the Google Analytics tracking code into the editor’sBefore marking:

将Google Analytics统计代码添加到WordPress的多方法插图18

Edit the header.php file in WordPress

Then, make sure you click the Update File button. The Google Analytics tracking code has now been added to WordPress.

3. Integrate Google Analytics and WordPress with Google tag Manager

Another way you can add Google Analytics to WordPress is to use Google Tag Manager. This actually applies to sites that contain scripts for a variety of purposes, not just analysis.

Google Tag Manager is a label management system. It allows you to quickly and easily update tags and code snippets on your website or mobile applications, such as those used for traffic analysis and marketing optimization.

Instead of editing the site code in WordPress, you can add and update scripts from the tracking Code Manager user interface. This reduces errors and eliminates the need for developers to be involved in configuring tags.

The easiest way is to use the free Google Tag Manager WordPress plug-in. It currently has more than 300000 active installations and five-star ratings:

将Google Analytics统计代码添加到WordPress的多方法插图19

Google Tag Manager for WordPress plug-in

You can download the Google Tag Manager plug-in from the WordPress plug-in library, or you can search for it under the plug-in gt; installation plug-in in the WordPress dashboard. Then you need to sign up for an Google tracking code manager account and create your first container.

After completing the above steps, you can copy the container ID from the Google tracking Code Manager control panel by navigating to the Admin tab and looking for a series of characters that begin with GTM:

将Google Analytics统计代码添加到WordPress的多方法插图20

Find the container ID in the Google tracking code manager

Then return to your WordPress site and paste your Google Tag Manager ID into the relevant fields on the plug-in settings page. You can get there by navigating to Settings & gt; Google Tag Manager:

将Google Analytics统计代码添加到WordPress的多方法插图21

Add the container ID to the Google tracking code manager plug-in

Any tags you set in Google Tag Manager, including tags for Google Analytics, can now be run on your WordPress site through plug-ins.

4. Synchronize Google Analytics locally for performance reasons

The last method you can use is to synchronize Google Analytics scripts locally on your own server. Note that this method is not supported by Google.

However, you may want to do this for several reasons. First, synchronizing Google Analytics locally can reduce your external HTTP requests. In addition, you will have complete control over the caching of files, so you can use the cache header of your own server.

This is important to improve the performance of the website. If you use Google PageSpeed Insights, you may see a “serve static assets using valid caching policy” warning for your Google Analytics script:

将Google Analytics统计代码添加到WordPress的多方法插图22

Google Analytics warning example

The problem is that by default, Google Analytics has two hours of caching, as you can see in the warning above. This is probably because if Google eventually needs to modify something, it wants all users to access those changes as soon as possible.

By hosting Google Analytics scripts on your own server, you can change the cache time to improve performance.

Use Complete Analytics Optimization Suite to synchronize Google Analytics locally

First, we recommend using Complete Analytics Optimization Suite (CAOS), a free plug-in created and developed by Daan van den Bergh. It currently has more than 20000 active installations and has a five-star rating:

将Google Analytics统计代码添加到WordPress的多方法插图23

CAOS | hosts the Google Analytics WordPress plug-in locally

You can download it from the WordPress plug-in library or search for it under the plug-in gt; installation plug-in in the WordPress dashboard.

CAOS allows you to host your Google Analytics JavaScript file (analytics.js) locally and keep it updated using wp_cron (). Other features enable you to:

  • The IP address of anonymous visitors.
  • Set the adjusted bounce rate.
  • Change the location (header or footer) of the Google Analytics script.

You need to deactivate any installed analysis plug-ins before using them.

When you install CAOS and enter your Google Analytics tracking ID, the plug-in adds the necessary code for Google Analytics to your WordPress site. It then downloads the analytics.js file, saves it to your server, and updates it using the scheduled script in wp_cron ().

We recommend that you set the script to load in the footer by going to Settings & gt; Optimize Analytics and selecting the Footer option under Position of tracking code:

将Google Analytics统计代码添加到WordPress的多方法插图24

Synchronize Google Analytics settings locally

It is important to note that CAOS does not apply to other Google Analytics (Analytics) plug-ins.

Use Perfmatters to synchronize Google Analytics locally

Another plug-in available for local analysis is Perfmatters. This is an advanced website performance optimization plug-in created by Brian Jackson and his brother Brett:

将Google Analytics统计代码添加到WordPress的多方法插图25

Perfmatters plug-in

Among its many features, there is also an option to synchronize the Google Analytics locally by entering your trace ID. Like CAOS, you can set the script to load in the footer instead of the header.

Summary

Google Analytics is an important tool for site owners and managers, although it is not the only available analysis tool you can use.

Tracking your site’s user activity, recommendation sources, and other data is key to expanding your audience and brand. To connect Google Analytics to your WordPress site, you can use one of the following methods:

  1. Add Google Analytics to WordPress using a plug-in (Site Kit or GA Google Analytics).
  2. Manually connect Google Analytics and WordPress by adding code directly to your topic.
  3. Integrate Google Analytics and WordPress using Google Tag Manager (it’s easy to use plug-ins such as Google Tag Manager for WordPress).
  4. Synchronize Google Analytics locally (using CAOS or Perfmatters plug-ins) for performance reasons.
Disclaimer: All articles on this website, unless otherwise specified or marked, are original and published on this website. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of this site. If the content on this website infringes on the legitimate rights and interests of the original author, you can contact us for assistance.