How To Add Google Analytics To Your Website Using Google Tag Manager

Google Analytics (GA) can open a sea of information for your website. To implement GA, a javacript code (or tag) is added to each and every page of the website. The code can be directly inserted into every page, in the header file of your website (header.php for wordpress sites) or through some plugin (if your site is on wordpress).

Another way of adding Google Analytics is through tag manager. Tag manager loads all the tags asynchronously and this does not affect the loading speed of your website.

If you have already setup your tag manager account, then proceed with adding analytics to it.

Adding Google Analytics through GTM

To add Google Analytics through tag manager, you need to note down your UA tracking ID. This ID is available under the admin section on Google Analytics. Just log on to Google Analytics, click Admin, go to Property and then click on tracking code. Here, you will find your tracking ID which begins with “UA-”.

Creating User-Defined Variable for Tracking ID

Before we create the actual tag for adding analytics in GTM, we will create a user defined variable for sending the click data captured on the website, back to Google Analytics. To create this User Defined Variable, read on.

  • Click Variables and then click New under User Defined Variables.
  • Name the variable UA Tracking ID (or something similar). Now click Variable Configuration.
  • Scroll down on the window that pops out from the side of the screen and locate Utilities. Click Google Analytics Settings. Under Tracking ID, copy paste your Google Analytics Tracking ID. This can be found on the admin panel in Google Analytics (Admin – Property – Tracking Info – Tracking Code – Tracking ID). This ID starts with UA.
  • Leave Cookie Domain as “auto”. Click on More Settings and scroll down to Advertising. It is recommended that you click on “Enable Display Advertising Features”. This will help you with your Remarketing efforts at a later date. Your configuration screen shall look something like shown below. Now click Save.

Adding Google Analytics Through Google Tag Manager Screenshot

  • The new variable (UA Tracking ID) should appear under the list of User Defined Variables.

Creating Tag for Analytics

Now to create the tag in GTM, follow the steps below.

  • Login to Google Tag Manager.
  • Click Tags and then click on “New” button.
  • Name the tag “UA Analytics Tracking” (or some other logical name)
  • Now click on Tag Configuration and choose tag type as “Universal Analytics”
  • Now since we are interested in finding out the total number of page views on our site, select Track Type as Page View.
  • Under Google Analytics Settings, select the user defined variable that you had created in the above section – {{UA Tracking ID}} (or whatever name you had given to this variable)
  • Ignore Advance Settings for the time being.
  • Click on Triggering and then choose the trigger “All Pages”. This is because we want this tag to fire on all pages.
  • Test the tag before you deploy it.

Testing and deploying the tag

  • Click Preview near the top right corner of the main dashboard. This will open the dashboard in Preview Mode for testing the tag.
  • Now open a new tab on the same browser window and enter URL of your website in the address bar.
  • Once the page loads, the screen will get divided in two parts. The upper half will show your webpage whereas the lower half will show the tags which have fired as well as the ones which have not fired.
  • The tag that you just created – UA Analytics Tracking – should be displayed under the Tags Fired on this page.
  • Log on to Google Analytics. Under Real Time tracking, you should be able to see an active user. (Ensure that there are no filters to block traffic from your own IP).
  • Once you are satisfied that the tag is firing correctly, click on the Submit Name your version and add a description of the changes you made, tags/variables/triggers that you created in this version etc. and click Publish. It is important that you thoroughly check the tag before publishing it to the live site.

All done! Happy Tagging!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *