Are you looking for a way to add Google Analytics to Astra Theme? If you are a newbie to the Astra theme and also new to Google Analytics and don’t know how to create a Google Analytics Account.
Here is the process to add Google Analytics tracking code to your WordPress website theme.
I will present you with two simple ways to help you achieve this goal and let you keep track of how people interact with your website.
I assume you know about Google Analytics by now and have already set up your tracking code.
Here we are using the code of the latest Google Analytics version i.e. Google Analytics version 4 aka GA4.
If not then here is a quick way to get a tracking code.
- Go to analytics. gooogle.com.
- Go to Admin Menu > Property Panel.
- Under Property, go to Data Streams.
- You will see your site name, Click on it.
- Now, go to View tag instructions.
- Click on Install Manually.
- Now, you will get a Google tag (gtag.js) tracking code.
Steps to Add Google Analytics to Astra Theme
here we will use the Astra Pro version to enable the Custom Layouts Module via Astra Options.
If you don’t have the Astra Pro version then get it right now.
I assume you already have activated the Astra Pro plugin so let’s get started.
1. Activate Custom Layouts Module
We need to add code via Hooks in Astra Theme in order to add analytics code on our website. so, let’s activate the Custom Layouts Module.
Go to Astra > Astra Pro Modules > Custom Layouts > Activate
2. Add New Custom Layouts
Let’s add New Hook from Custom Layouts.
Go to Astra > Custom Layouts > Add New
.
Select Hooks from the available options and that will create a new Custom Layout Hook.
To add analytics code, click on Enable Code Editor Option located at the top of the box.
Here, Add the Title for the Google Analytics code.
Under Layout Option, choose the Hooks option.
Now, you will be able to see more Hooks options.
3. Custom Layouts Settings for Google Analytics Code
- Under Action, Select wp_head.
- Leave Priority as it is.
- Under Spacing leave as it is.
- Select Entire Website under the Display On Option.
- Under Responsive Visibility leave it as it is.
- For other settings leave it blank.
- Finally Hit Publish Button.
Recommended Reading:
- How to Add JavaScript in Astra Theme?
- How to Add Floating WhatsApp Button in Astra Theme?
- How to Add Last Updated Date in Astra Theme?
- How to Add Social Sharing Buttons in Astra Theme without Plugin?
- How to Display Related Posts in Astra Theme?
FAQs
Do you need a plugin to add Google Analytics to Astra Theme?
No, you don’t need any external plugin to add a Google Analytics script to Astra Theme.
Can we use Hook Method to add Google Analytics to Free Astra Theme?
No, you need to Astra install the premium module to add the Google Analytics code. You can also install free plugins like Insert Headers and Footers or WP Code.
What are lightweight options to install Google Analytics code?
Flying Analytics and CAOS are two lightweight options to integrate analytics into your website which help to host the analytics script locally.
At the End
Adding Google Analytics is easy to do with the Astra Pro Addons which comes with multiple features enabled.
Just install the plugin and enable all the required features like Custom Layouts, etc.
This is one of the easiest ways to add analytics code in Astra Pro Theme and you can totally avoid using any analytics plugin.
Let me know your thoughts in the comment section below.
For the FAQs you 100% can add a hook to enqueue the gtag.js script in your functions.php. Why wouldn’t you be able to do this? I did it for one of my sites and it works perfectly fine.