How to Add Google Analytics to GeneratePress Theme?

In this article, we are going to learn to add Google Analytics to GeneratePress Theme. We are going to use different methods to implement the analytics code on our WordPress site.

My goal is to load the website faster and I am achieving the best loading time using cloud hosting, caching plugin, and GeneratePress Theme.

GTMetrix Score of WPLogut Blog

As I have been using the GeneratePress Premium version in this WPLogout blog. Though there is a free GeneratePress version but I opted to go with paid Theme.

Moreover, you can add a tracking code using these methods in both the free and paid versions.

While creating a website you need to take care of various things and adding Google Analytics code is one of them.

Google Analytics helps to track our website traffic, it is the best and free tool available in the market to track website visitors.

Add Google Analytics to GeneratePress Theme

In this Google Analytics to GeneratePress guide, we are going to use two different approaches:

  • Adding Google Analytics using Plugin.
  • Adding Google Analytics Without Plugin
How to add Google Analytics to GeneratePress

To get tracking ID/Code you need to visit Google Analytics and set up the account. You can track up 100 websites from a single Gmail account.

Note: Use only one method to add Google Analytics code on your site and check the real-time to make sure the code is tracking the visitors. If you are using a caching plugin, don’t forget to clear the Cache.

Get the tracking ID/Code from

Google Analytics > Admin > Tracking Info > Tracking Code

You will see something like this ID/code as in the screenshot.

Google Analytics Tracking Code Example

1. Add Google Analytics to GeneratePress using Plugin.

You can find plenty of plugins where you can add Google Analytics easily. In this method, we are going to try 2-3 plugins. Let’s try a lightweight approach so that the loading time of our website doesn’t get much affected. so let’s get into the plugins.

Insert Headers and Footers Plugin

Insert Headers and Footers plugin is a lightweight plugin that helps to insert code like Facebook Pixel, Google Analytics, also custom HTML and JavaScript code.

This plugin has two sections to insert codes: one is at header and another is at the footer. The plugin has over 900,000+ active installation

  • Copy the Analytics code
  • Go to Settings > Insert Headers and Footers
  • Paste the script in the header.
  • Hit the Save button.
Adding Google Analytics Code using Insert Headers and Footers Plugin

CAOS Plugin

CAOS stands for Complete Analytics Optimization Suite, it is developed by Daan van den Bergh. I have been using CAOS WordPress plugin in my blog.

It is a plugin that helps to host our analytics code locally. CAOS helps to score higher in page speed test tools like GTMetrix, Pingdom, Google PageSpeed Insights, etc.

CAOS Plugin
  • Copy the Analytics Tracking ID
  • Go to Settings > Optimize Analytics
  • Paste the Google Analytics Tracking ID.
  • Choose the position of tracking code to load in the Header.
  • Use CDN URL in the CAOS settings if you use CDN (I am using BunnyCDN)
  • Adjust other settings according to your needs.
  • And Hit the Save Changes button.

Flying Analytics Plugin

It is similar to the CAOS plugin. It is a new plugin in the market as compared to CAOS. This plugin also helps to host analytics code locally that will speed up the WordPress website.

Flying Analytics
  • Copy the Analytics Tracking ID
  • Go to Settings > Flying Analytics
  • Paste the Google Analytics Tracking ID.
  • And Hit the Save Changes button.

Also Try: Host Google Fonts Locally in WordPress

2. Add Google Analytics to GeneratePress Without Plugin

If you are using the free version of GeneratePress then follow Method 1 mentioned above. We are going to use Hook available in GeneratePress Premium Theme.

Adding a New Hook in GeneratePress
  • Activate the Elements Module. Appearance > GeneratePress > Elements > Activate
  • Copy the Analytics Code.
  • Go to Appearance > Elements > Add New
  • Choose Element Type as Hook. Name it as Google Analytics.
  • Paste the Code in the Hook.
  • Go to the Hook Settings and choose the hook to display in wp_head.
  • Go to the Display Rules and select Location as the Entire Site.
  • Hit the Publish button.

At the End

So which method are you going to try?

Will you use the plugin method or without plugin to add Google Analytics code in GeneratePress Theme.

I have used the first method using the CAOS plugin in the blog. I am going to the Flying Analytics plugin in my other blog.

I hope you will get rid of Fix Leverage Browser Caching Warning in speed testing tools.

Happy Blogging, Happy Optimizing.

Share:

I am obsessed with WordPress and write articles about WordPress Speed Optimization, SEO, and Blogging. I mostly publish tutorials on GeneratePress, Astra, Kadence, and GenerateBlocks.

8 thoughts on “How to Add Google Analytics to GeneratePress Theme?”

  1. I was also using CAOS plugin for the last 1 year but it conflicting to display Google Adsense ads on mobile devices so now I’m using Flying Analytics Plugin.

    Reply
  2. Hi, I’m already using Google Analytics using Hooks in GeneratePress. Now I’m planning to add Adsense code using the similar method (Hook -> wp_head), will there be any conflict in doing this? since I’m adding both the codes with Hooks in the same area (wp_head).

    Reply
  3. HI MENE APNI WEBSITE KE SARI PLUGIN OR THEME AND WORDPRESS
    KO UPDATE KIYA HAI OR AD SHOW HONA BAND HO GAYE HAI KYA MUJHE AD CODE DUBARA INSERT KARNA PADEGA KYA IS TARIKE SE AS CODE INSERT KAR SAKTA HOON

    Reply
  4. Superb Article, I have one question, is it possible to not track views from me and other logged-in users? I know there is a display rule to show logged-out users. Doest it mean all site visitors or just the users who just have logged out?

    Reply
    • Hi Rahul,
      I think you can use Block Yourself from Analytics Chrome extensions, it’s the easiest method.
      Other than that, you can Create an IP address filter in analytics.
      Thanks

      Reply

Leave a Comment