Add Google Analytics to Astra WordPress Theme

Chart with text "Add Google Analytics to Astra Theme"

In this post I’ll show you how to add Google Analytics to Astra WordPress theme.

This post assumes that you have created your website using Astra and are ready to start collecting visitor data.

You’ll want to add Google Analytics tracking code to your website so that you can track basic visitor data such as user behavior, demographics, top landing pages and more.

But before you can add that code, you need to have a Google Analytics account.

Create Your Google Analytics Account

If you don’t yet have one, you can create an account at https://google.com/analytics and set up a website property in your Analytics account.

From there you can obtain your website tracking code:

  1. Log into Google Analytics
  2. Go to Admin>Property
  3. Under Property Column, click Tracking code
  4. And then Ctrl + C to copy the code or Cmd + C to copy the code on a Mac

Next, make sure you have a good backup!

Now we are ready to add Google Analytics to Astra.

There are three ways that you can add the code depending on whether or not you are using the free Astra theme.

And I’ll show you all three ways.

Method 1: Using the Free Astra Theme

If you are using the free Astra theme, you will need to install and activate the Astra Hooks Plugin.

Install Astra Hooks Plugin

  • From the dashboard Go to Plugins>Add New
  • Type Astra Hooks in the Search plugins box
  • Click Install
  • Click Activate

Next we need to add the tracking code into the customizer.

And we’ll want to place that tracking code into the website header.

Add Google Analytics to Astra Website Header

  • Go to Appearance > Customize > Scroll down to Hooks
  • Click Header and in wp_head paste your tracking code
  • Click Publish

If you need more detailed instructions, you can refer to the following short video.

Short Demo on How to Add Google Analytics to Astra WordPress Theme

And now the Google Analytics tracking code has been added to your site using the Astra Hooks plugin.


Method 2: Using Astra Pro Plugin

If you are using the paid Astro Pro plugin, it is recommended that you use the custom layouts module to add Google Analytics to Astra.

Remember, for this method, you need to have the Astra Pro Plugin installed and activated. You’ll also need to have the custom layouts module activated.

I’ll show you how to do both.

From the dashboard Go to Appearance > Astra Options

Note the available modules for Astra Pro as per the following screenshot.

Scroll down and make sure custom layouts is activated.

Screenshot of Available Astra Pro Modules

Next we want to create a new custom layout.

From the dashboard:

  • Go to Appearance >Astra Options > Custom Layouts
  • Click Add New and give the layout a name such as ‘Google Analytics’
  • Click Enable Code Editor
  • Paste your analytics tracking code
  • Next, scroll down to Custom Layout Options and choose Hooks
  • In the action drop down choose wp_head
  • Scroll down to Display On and choose Entire Website
  • Click Publish

See the following screenshot for settings but make sure you are using your tracking code ~ not the sample code in the screenshot!

Screen Shot of Astra Custom Layout Options
How to Add Google Analytics to Astra Using Astra Pro Plugin

The tracking code has now been added to your site using Astra Pro.

For your convenience, you may want to refer to the following video that demonstrates both of these methods.


Method 3: Using Insert Headers and Footers Plugin

Finally, some people find it easier to use the Insert Headers and Footers plugin to add Google Analytics to the Astra WordPress theme.

The benefit to using this plugin is that it is theme independent.

That means if you ever switch themes, it’s a safe way to retain your Google Analytics and any other tracking code.

Whereas if you have created a custom layout for Astra, when you remove that theme, you lose all the tracking code you added.

I hope that this tutorial has been helpful to you.

Print Friendly, PDF & Email

Similar Posts