How to Add Google Analytics in GeneratePress

I may earn a small commission from purchases made through product links in this article at no extra cost to you. I only recommend products I use now, have used in the past, or would use if there was a business need.


Last updated: May 26, 2021

If you’ve read my review of GeneratePress, then you know I’m a big fan of this WordPress theme. It’s fast, it’s super customizable, and most importantly, it’s as robust as it gets.

One question I get asked quite a lot is how to actually add the Google Analytics tracking code in GeneratePress.

The good news is that there’s no need to install another plugin for this task, and there’s also no need to edit any WordPress files. In fact, the process within GeneratePress is actually quite easy. You just need to know how to do it.

So let’s get straight into it.

Try GeneratePress

Adding Google Analytics in GeneratePress

The following steps assume you already have collected your Google Analytics tracking code, and you’ve got that ready to add to your GeneratePress powered blog.

Also note that you can use the exact same steps below to add the site-wide Google AdSense code.

1: Create a Hook Element

The first step is to create a new Hook Element. Navigate to Appearance, Elements, then Add New. Select Hook from the dropdownlist.

Create new Hook Element in GeneratePress

In the screen that follows, you can edit the new Hook element.

2: Add Your Google Analytics Code

In the editor box, copy and paste your Google Analytics tracking code:

Paste Google Analytics tracking code in Hook editor

Make sure you give this new Hook Element an appropriate name, such as “Google Analytics”. I know, it’s not very original, but you get the point.

3: Configure the Hook Settings

The next step is to configure the Hook element such that the Google Analytics tracking code will be added to the HMTL head element of all pages in your website.

In the dropdownlist located next to Hook, select wp_head. This adds the tracking code to the head element of your HTML output, which is where you want it to be.

Configure the Hook settings

In the Display Rules tab, next to Location, select Entire Site from the dropdownlist. This will, you guessed it, add the tracking to all pages of your GeneratePress website.

Include Google Analytics code in entire site

Have a look through all your settings, and move on to the next step.

4: Publish the Hook Element

Once your Hook Element is created and configured the right way, you can hit that publish button.

Publish the Hook element

Once it’s published, visit some of your posts, and also your home page, to test that the tracking code is present in the HTML source code.

Right click on the page you’re on, select View Page Source, and do a quick search for (a word or phrase in) the tracking code. If you can find your Google Analytics code, you’re all set!


Subscribe now and receive tips and thoughts on blogging, SEO, and WordPress straight to your mailbox.

AJ Mens

I am a corporate IT nerd turned digital marketing enthusiast, specializing in SEO and content strategy. I have been blogging since 2015, and my aim with Blog Pioneer is to help you achieve success online. Connect with me on Twitter and LinkedIn.

Leave a Comment