How to Add Google Analytics in GeneratePress

We may get a small commission if you buy something through a link in our posts.


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

AJ Mens is a digital marketing professional specializing in WordPress, SEO, affiliate marketing, and content strategy. Following a career in IT, he has been involved in creating, growing, buying, and selling web properties since 2015.

AJ Mens on LinkedInAJ Mens on XAJ Mens on Facebook
Leave a Comment