Multiple Ways to Add Google Analytics Stats Code to WordPress

In this post, we'll discuss what Google Analytics does and how important it is to your website. Then we'll share four ways you can connect it to WordPress to start tracking activity.

Multiple Ways to Add Google Analytics Stats Code to WordPress

Many WordPress users are puttingGoogle AnalyticsDifficulty connecting to their WordPress site and they missed the opportunity to collect user data.

Fortunately, there are a variety of 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 post, we'll discuss what Google Analytics does and how important it is to your website. Then we'll share four ways you can connect it to WordPress to start tracking activity.

Introduction to Google Analytics

Before you start puttingGoogle AnalyticsBefore connecting to your WordPress site, it's best to understand what it is and how it works. In short, the platform monitors your site's activity and provides you with key data to help you improve it:

Google Analytics Home
Google Analytics Home

Using snippets of code inserted into the headings of each page of your website, Google Analytics collects a wide variety of information that can be categorized into five categories:

  • Real time: Shows what was happening on your site at the specific moment you viewed the report.
  • Audience: Include information about who is visiting your site, including demographics.
  • Get: Explain how your website gets traffic.
  • Behavior: Show what visitors are doing on your site, including button clicks and which of your pages are most popular.
  • Transformation: Advanced reports used in conjunction with Google Analytics goals for tracking activity such as email list subscriptions or e-commerce sales.

Examples of specific information you might find in a Google Analytics report include:

  • The number of active users on your site at any given moment.
  • How many people visit your site over time.
  • Age, sex and location of visitors.
  • Where your visitors are coming from (e.g., natural search, social media, etc.).
  • Which pages the visitor viewed and for how long.
  • Bounce rate, click-through rate and conversion rate.

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

Why Analytics Matter for Your WordPress Website

Analytics can be valuable for many different aspects of your website if you know how to make the most of them. Four key areas relevant to any type of website include:

  • Content Marketing Strategy. By considering your most popular posts, pages, products, or other content, you can determine what your visitors like best. Increasing page views and traffic is a matter of creating more of the types of content that resonate best with your audience (here's how to get started with keyword research and how to targetSEO optimization(WordPress).
  • Inbound Marketing. Knowing where your traffic is coming from can tell you which marketing strategies are working and which ones are declining. You can then focus most of your efforts and budget on the methods that produce the most results.
  • Audience Segmentation. Understanding your audience is key to effectively communicating with them to encourage conversions. Through analytics, you can create subgroups for targeted marketing.
  • User Experience (UX) Audit. User behavioral flows can reveal problems with your navigation or site design. Identifying underperforming content and pages with high bounce rates may help you improve problem areas.

If you run an e-commerce site, theisomerization (chemistry)The report also helps track sales and revenue.

As you can see, it's not always the numbers themselves that matter. It's how you apply the knowledge gained from Google Analytics that is of value. Solving problem spots and applying the best marketing techniques for your website can increase traffic, conversions, 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 a number of different ways.

In each case, we assume that you have already set up a Google Analytics account. If you don't, please create one , and then come back for the next step.

1. Using the Google Analytics WordPress plugin

The easiest way for most WordPress users to add Google Analytics to their website is to use the Google Analytics WordPress plugin. This method keeps you from having to edit your website's code.

For this purpose, we recommend three plugins:

Installing Google Analytics with Site Kit by Google

If you want to add Google Analytics to your WordPress site, Google has a simple and powerful plugin for you:Site Kit by GoogleThe

Site Kit by Google plugin
Site Kit by Google plugin

This free plugin connects Google Analytics to your WordPress site in just a few clicks, but that's not all. In addition to analytics, this plugin pulls data from other services provided by Google, such as Google Search Console, Google AdSense, and PageSpeed Insights , allowing you to build a nice dashboard based on Google as a data source.

Here's how to get started:

Install and activate the Site Kit by Google plugin, then click "Start Setup"Button.

Setting up the WordPress plugin Google Site Kit
Setting up the WordPress plugin Google Site Kit

Once that's done, you'll need to connect your WordPress site to your Analytics account.

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

Google Site Kit set up successfully
Google Site Kit set up successfully

After successfully connecting with your Google account, you'll be able to view data from Google Analytics and all the other services activated directly in your WordPress dashboard. Here's what it looks like:

Google Site Kit Information Center
Google Site Kit Information Center

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

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

Installing Google Analytics with GA Google Analytics

Jeff Starr's freeGA Google AnalyticsThe plugin boasts over 400,000 active installs and a five-star rating:

WordPress Plugin - GA Google Analytics
WordPress Plugin - GA Google Analytics

After installing and activating the Google Analytics WordPress plugin, you just need to add your Google Analytics Tracking ID in its settings. To retrieve your tracking ID, go to your Google Analytics account and click theAdmin::

Google Analytics admin tab
Google Analytics admin tab

existPropertylower case, selectTracking Infoand then clickTracking Code::

Access to Google Analytics tracking code under Property Information
Access to Google Analytics tracking code under Property Information

Your tracking ID will be displayed asUAbegins and is located at the top of this section:

Access to Google Analytics Tracking IDs
Access to Google Analytics Tracking IDs

In your WordPress dashboard, navigate to theSettings > Google Analytics. Scroll down toPlugin Settingsand add your tracking code to the relevant fields:

GA Google Analytics WordPress Plugin Settings Page
GA Google Analytics WordPress Plugin Settings Page

This plugin also allows you to choose whether you want to place tracking codes in the header and footer, add custom tracking codes, force SSL, disable tracking for admin users, and a number of other useful options.

After making adjustments to suit your needs, scroll down and click "Save Changes" button.Google Analytics should now be active on your WordPress site.

Installing Google Analytics with MonsterInsights

MonsterInsights offers a number of different programs depending on your needs. Sign up for MonsterInsights, choose the plan that suits you (paid) and then download the plugin. If you're just starting out and don't need too much power, you can also get started with MonsterInsights using MonsterInsights Lite (the free version). To do this, go to Plugins on the right side of the WordPress dashboard and then go toInstallation of plug-ins(Add New). Search for MonsterInsights in the search bar and to find the corresponding plugin, click "Installation(Install Now)" and click "activation(Active)".

Multiple Ways to Add Google Analytics Stats Code to WordPress

After downloading and activating the plugin, click "Insights", and then click "Settings", by clicking "Authenticate with your Google account ((Authenticate with Google Account)" button to authenticate Google Analytics on your website.

Multiple Ways to Add Google Analytics Stats Code to WordPress

You will then be prompted againchose/sign(Select/Login) your Google account. After selecting your Google account, a pop-up window will appear asking for permission to manage your account with MonsterInsights. ClickAccept(Accepted).

Multiple Ways to Add Google Analytics Stats Code to WordPress

Finally, all you have to do is select your website and click "Complete Authentication(complete authentication)".

Multiple Ways to Add Google Analytics Stats Code to WordPress

Now, you can create a new file by clicking on the "Insights", and then click "Reports", it's easy to view reports about website traffic and analytics from within the WordPress dashboard. All reports look great and are very easy to understand.

Multiple Ways to Add Google Analytics Stats Code to WordPress

2. Manually connect Google Analytics and WordPress using code

If you don't want to use the plugin, you can use it via yourfunctions.phpFile Adding Google Analytics tracking code directly to your WordPress theme is also fairly simple.

If you do it the manual way, you must use a child theme so that your tracking code is not overwritten every time you update your WordPress theme. However, it's always a good idea to make a backup before making any changes.

Once your child theme is active, you will need to add a new theme to theheader.phpEnd of document</head>Paste your Google Analytics tracking code before tagging.

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 access your tracking information from theGoogle Site TagCopy the script in the box under:

Copy Google Site Tag Code
Copy Google Site Tag Code

To add it to your WordPress site, go to theAppearance > Theme File Editor. If your child theme inherits the template files from its parent theme, you won't see theheader.php. You can access it by clicking the name of the parent theme in the file list:

Child Themes WordPress Theme Editor
Child Themes WordPress Theme Editor

Find and selectheader.phpAfter that, paste the Google Analytics tracking code into the editor in the</head> Marker before:

Editing the header.php file in WordPress
Editing the header.php file in WordPress

Then, make sure you click theUpdated documentsGoogle Analytics tracking code has now been added to WordPress.

3. Integrating Google Analytics and WordPress with Google Tag Manager

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

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

Instead of editing site code in WordPress, you can add and update scripts from the Tracking Code Manager UI. This reduces errors and allows you to configure tags without having to involve developers.

The easiest way to do this is to use the freeGoogle Tag Manager WordPress Plugin. It currently has over 300,000 active installs and a 5-star rating:

Google Tag Manager for WordPress plugin
Google Tag Manager for WordPress plugin

You can download the Google Tag Manager plugin from the WordPress plugin repository, or you can download the Google Tag Manager plugin from the WordPress dashboard in thePlugins>Install PluginsSearch for it under. Then, you need to sign up for a 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 theAdmintab and look for the tab that begins withGTMA series of characters at the beginning:

Finding the container ID in Google Trace Code Manager
Finding the container ID in Google Trace Code Manager

Then return to your WordPress site and paste your Google Tag Manager ID into the relevant field on the plugin settings page. You can do this by navigating to theSettings > Google Tag ManagerGetting there:

Adding Container IDs to Google Tracking Code Manager Plugin
Adding Container IDs to Google Tracking Code Manager Plugin

Any tags you set up in Google Tag Manager (including tags for Google Analytics) will now work on your WordPress site via the plugin.

4. Local synchronization of Google Analytics for performance reasons

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

However, there are several reasons why you may want to do this. First, synchronizing Google Analytics locally will reduce your external HTTP requests. Additionally, you'll have full control over the caching of your files, so you can use your own server's cache headers.

This is important for improving site performance. If you're using Google PageSpeed Insights, you may see a "Serve static assets with an effective caching policy" warning for your Google Analytics scripts:

Example of a Google Analytics warning
Example of a Google Analytics warning

The problem is that, by default, Google Analytics has a two-hour cache time, as you can see in the warning above. This is likely because if Google ends up needing to change something, it wants all users to have access to those changes as soon as possible.

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

Synchronizing Google Analytics locally with Complete Analytics Optimization Suite

First, we recommend usingComplete Analytics Optimization Suite (CAOS), which is a free plugin created and developed by Daan van den Bergh. It currently has over 20,000 active installs and a five-star rating:

CAOS | Locally Hosted Google Analytics WordPress Plugin
CAOS | Locally Hosted Google Analytics WordPress Plugin

 You can download it from the WordPress plugin repository, or from the WordPress dashboard in thePlugins > Install PluginsSearch for it under.

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

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

You will need to deactivate any installed analytics plug-ins before you can use them.

When you install CAOS and enter your Google Analytics tracking ID, the plugin adds the necessary code for Google Analytics to your WordPress site. It will then download the analytics.js file and save it to your server and update it using a scheduled script in wp_cron().

We recommend setting the script to load in the footer by going to theSettings > Optimize Analyticsand selectPosition of tracking codelowerFooterOptions:

Synchronize Google Analytics settings locally
Synchronize Google Analytics settings locally

Be sure to note thatCAOS does not apply to other Google Analytics pluginsThe

Synchronizing Google Analytics locally with Perfmatters

Another plugin available for local analysis isPerfmatters. This is a premium site created by Brian Jackson and his brother Brettperformance optimizationPlug-ins:

Perfmatters plugin
Perfmatters plugin

Among its many features is the option to synchronize Google Analytics locally by entering your tracking ID.As with CAOS, you can also set scripts to load in the footer instead of the header.

Summary of this article

Google Analytics is an important tool for website owners and administrators, though not the only available analytics tool you can use.

Tracking your site's user activity, referral 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 plugin (Site Kit or GA Google Analytics).
  2. Manually connect Google Analytics and WordPress by adding code directly to your theme.
  3. Integrate Google Analytics and WordPress with Google Tag Manager (easy with plugins like Google Tag Manager for WordPress).
  4. Synchronize Google Analytics locally for performance reasons (using CAOS or Perfmatters plugin).

Original article by Woo-won SEO, if reproduced, please specify the source: https://www.ycsu.com/en/317/

Like (0)
Donate WeChat Sweep WeChat Sweep Alipay Sweep Alipay Sweep
佑元SEO's avatarYouyuan SEO
Previous October 15, 2024 at 10:41 am
Next November 19th, 2024 at 10:19 am

Leave a Reply

Please Login to Comment
microsoft