Add Google Analytics To WordPress | WordPress 101
Welcome to the WordPress 101 series. So far in this series, we’ve learned how to install a new WordPress theme, plugins, configure the homepage, create navigation menus, and so on. With this information, we should be able to launch our website. It is now time to prepare our website for traffic analysis so that we can make better decisions and have a complete picture of what is going on with our website.
Search engines will begin delivering visitors to your website once it is operational and has high-quality content. As the amount of material on the website grows, so does the number of visitors and engagement. For understanding where your visitors came from, how much time spent on a particular page, the links they clicked, and a lot more deep information that can help create better user experience and deliver you better results.
If the website is an eCommerce store, then the analytics system is a extremely useful as it can help increase sales. You can track campaigns on social media and track each of the campaign through analytics system like Google Analytics.
Traffic Analysis Solutions
Google Analytics & Statcounter
There are innumerable analytics solutions available on the Internet, but Google Analytics and Statcounter are two of the most widely used. Whereas Statcounter provides a straightforward glance at your website visitors, Google Analytics delivers a wealth of information about them.
Integrate Google Analytics with WordPress site
Integrating Google Analytics is easy. Let’s start with creating a Google account, skip it if you already have one and login. Go to Google Analytics and it’ll provide a simple setup wizard.
Type the account name and check or uncheck data sharing. Press Next.
Next up enter the property detail. A property can be a website or an android/iOS app. For this example, I am going to host a test website. So I type the property name as the URL of the website. Select the reporting timezone and click Next.
Enter your business information. It’s not mandatory, so you can leave it all and click Create.
Lastly, select your country, read the terms & conditions, and accept it. The initial setup is over.
Now select the type of the property you want to integrate Google Analytics with. In this case, I select Web.
Enter the URL of the website, name of the website, and toggle on/off enhancements. You can capture Page views, Scrolls, Outbound clicks, etc. So you can toggle them all on or off or select the specific ones you want and click Create stream.
Now there are two ways you paste this code in your website header. First, copy the code and paste it in the header of your website or use Google Tag Manager. I will explain both methods in this article.
Let’s start with the first one. Copy the code and paste it in the header. Here is how to do it –
Login to your WordPress site and manage to paste the above code so that it is distributed on each page of your website. Many WordPress themes provide a simple setting for adding custom code or scripts in the header.
In case your theme does not have this feature, you can use a plugin that allows to add code to the header and footer. You can install Insert Headers and Footers. From the admin sidebar, go to Settings > Insert Headers and Footers. Now paste the Google site tag or gtag.js in the header. That’s all! You have successfully integrated Google Analytics with your WordPress site.
Using Google Tag Manager
The above method is simple but as you need to integrate more and more services with your WordPress site, it’ll be difficult to manage third-party scripts. Google created a tool to easily install tags across your multiple sites from one platform, Google Tag Manager. Head over the website, login to your Google account and click Create Account (Google Tag Manager).
Enter the Account Name, country, website URL, platform, and click Create.
Now it’ll show you the code to be pasted in the WordPress site’s header and footer. You must be asking why not directly paste the analytics code? Well, as I said you can control multiple websites from GTM platform and most importantly can control the individual scripts which otherwise aren’t possible using the above WordPress plugin.
Once you have paste the above GTM code in the header and body of your website, your website is integrated with your site. Switch to GTM tab, click OK. Now you will see the GTM dashboard. Click New Tag as highlighted below.
Now will slide in the following window.
Enter the name of tag. The second selection is important one. Google Tag Manager allows you to easily integrate different inhouse products such as Analytics or third-party products using predefined templates. So we can select the Google Analytics: GA4 Configuration and it’ll allow you to integrate Google analytics with your site. But for this article, we will use gtag for Analytics integration.
So select Custom HTML from the tag type list. Paste the Google Analytics code (gtag.js) in the HTML box.
Now scroll down and click Triggering box. This is why GTM is useful. With GTM you can control when a script should load and where. I select All Pages out of the three predefined triggers. It means the script will load on all the pages. You can also create your own trigger by clicking the + icon on the top right corner.
Select the trigger and click Add. Click Save to save the tag settings.
It’s not done yet. Your tag has been added but it won’t go live until you hit Submit. Before submitting it to the site, you can preview how the website would look with the script. Click Preview, enter your website URL, and click Connect. If you GTM code correctly, your website will be connected and then you can apply all the changes by clicking the Submit button on the GTM dashboard.
Now GTM will load the Google Analytics script each time when a user visits on any page of your website. Similarly, you can add any other tags such as Statcounter, Google Adsense, Google Search Console etc.