Understanding user acquisition, as well as user behavior on your website, is crucial to its success. Google Analytics is a wonderful free tool to start tracking audiences to your website or app and most website owners are familiar with it. However, in reality, websites rely on various other tags or scripts for various marketing reasons as well.
Tag managers are now a better way of managing multiple tags embedded in your site. Let’s have a look at how would one go about installing Google Analytics with Google Tag Manager on a WordPress site.
Before we dive deep into this, for those who are new to tag managers, let’s understand what tag managers are.
What is a tag manager?
To understand a tag manager, let’s look at how one usually goes about adding any marketing tags to a site. Assume you have a site and now you want to start tracking users using Google Analytics. You get hold of the script provided by Google and then insert that tag on every page before the closing tag of the code.
Now say, a few days later, you also want to track Facebook visits. Facebook would hand you over another set of script which again you will have to add at various places on the site. How about a third tag, say Twitter? Well- you get the idea. One has to always tinker with the code every time a new script or tag has to be added.
What if we could have one script that’s added in the head of the website, which then takes care of injecting all other tags as and when needed. And that’s where a tag manager comes to play.
When we start using the tag manager, we inject one script to our website or app. Then within the console or dashboard of our tag manager, we can program various other tags like Google Analytics, Facebook, Twitter, Criteo, or any third-party script to be injected in real-time and also based on some logic you could define.
Tag manager thus keeps our code clean and helps us manage tag injection only as and when it’s required on the fly.
Why should you use a tag manager with WordPress
With the help of a tag manager for WordPress, one has to only manage one tag on the WordPress website.
Once the Tag Manager is in and functional, for most new future tags, you can take the help of Tag Manager Dashboard and program the tags to be injected. This keeps our WordPress theme much more maintainable.
Getting started with Google Tag Manager
Google provides a great tag manager, popularly known as- well, “Google Tag Manager“. Head over to tag manager.google.com and sign up with your Google Account. Just like Google Analytics, one can grant access to other users once it is setup.
Tag managers include Containers. Containers include tags, rules, and conditions when and where your tags will be triggered.
Container ID will help you identify the tag manager’s container on every website you install Tag Manager.
- Once you have signed in to Tag Manager, Click Workspace.
- On the top of the window, you should find your Container ID.
- Clicking on the container ID will help you get the Tag manager Installation code.
This code now should be included on the head of every page of your website or other digital property like Apps.
For websites, get the script part and paste it before the closing head tag. And no script part goes after opening of body tag.
The no script part will make sure this is taken care of when the browser does not allow scripts to be executed.
How to Include Google Tag manager code in WordPress
In cases of WordPress, you have a choice to include the files directly in the child theme’s header.php or the main theme’s header.php.
Any changes in header.php of parent theme are lost on updates of the theme. So it’s best to use a child theme. In scenarios where you proceed with making changes directly on the parent theme, you might have to redo them as and when the theme is updated.
Installing GTM or Google Tag manager on WordPress without plugins.
- Make sure you backup your theme files before you make any changes.
- Head over to Appearance – under your WordPress Dashboard.
- Within Appearance, look for Theme Editor.
- Now select the appropriate theme and then select the header.php file.
- Within Header.php, you can now place the script part of the tag manager code before the closing head tag and the non-script part of the tag just after the opening body tag.
Installing GTM or Google Tag Manager on WordPress with plugins.
Many plugins to implement Google Tag manager are available.
Most plugins will ask you to provide Google Tag Manager ID or container ID, which begins with ‘GTM-‘ followed by some characters like ‘XXXX’. You can get hold of this from the Google Tag Manager Dashboard.
Once the ID is provided to the plugins, the tag should be in as soon as you activate them.
Few Popular WordPress plugins to insert Google Tag Manager on a WordPress site are:
Deploy Google Analytics tags from Tag Manager
Now once you have Tag Manager implemented, it is time to start injecting tags using the Tag Manager dashboard.
We’ll look at how to install Google Analytics using Google Tag Manager. Head over to the tag manager and login to your dashboard. Select the workspace.
- From the Workspace, Click New tag and select Universal Analytics under Tag Configuration
- Select “Page View” as your Track type, as we look to measure what pages user visit.
- Now create or select a Google Analytics Setting Variable and enter the Google Analytics ID from your Analytics Tag. This ID looks like ‘UA-XXXXX…’.
- For beginners, leave the rest to default, and click save.
Now we have set up the tag, however, GTM does not know when to trigger it. We’ll also have to define the triggering point.
Click Triggering and choose a trigger that will make the defined Google Analytics tag inject in your website. For our case, the triggering will be on All Pages- Page View.
Once this is done, you now need to deploy or submit the changes to your workspace. Hit Submit at the top hand right side to deploy the changes.
If your website has the Google Tag manager successfully installed, you should now see the Google Analytics tag firing on every page view. How would you test the firing of the Google analytics tag?
Test the tag manager setup on your WordPress site
Once GTM has been set up and Google analytics is firing data on page views, you should start seeing data in your “Google analytics dashboard”.
One way to test the implementation is to head over to Real-Time View in Google analytics and then open your site or refresh the page, to notice for any increments on the real-time visitor counter.
Hopefully, the above has helped you understand Tag Managers and how do you go about installing Google Analytics with Google Tag Manager.