Igor Simic
3 years ago

How to install Google Analytics using Google Tag Manager


Google Analytics can be installed using Google Tag Manager and can be fired on specific/custom event. In this case we will use custom event from Data Layer defined in JavaScript. Example that you are going to see here is implementing this in Matang - Wordpress Angular Material Design Theme

Video how to install:
https://www.youtube.com/watch?v=p23JDAkA8Xw


Steps:
1. Install Google Tag manager to your site

2.Connect Google Analytics account with your Google Tag manager account:
  •     if you need to create new GA property here is how
  • Admin->Tracking Info->Tracking code and copy  Tracking ID
  • Go to google Tag Manager Account and create Variable
    • Variables->new->enter name->select variable->choose constant->paste your Analytics Tracking ID   and save it
3. Create another variable for matangUrl which is the DataLayer variable representing current URL of visiting page
  • Variables->new->enter_name->choose variable->select Data Layer->paste matangUrl in Data Layer Varible Name

4. Create a trigger based on Data Layer event, in this it is going to be page load event named (in JS DataLayer Object) as matangPageLoad
  • Triggers->new->enter_name->choose a trigger->select custom Event and paste your event name (in our case it is matangPageLoad) and save
  • select some custom events and set "event - equal - matangPageLoad"

5. Create Google Analyitcs Tag
  • Tags->new->enter_name->Tag configuration->select Universal Analytics
  • in Analyitcs options select Track Type -> event
  • click on "Enable overriding settings in this tag"
  • click on Tracking ID and select your GA Tracking ID variable
  • click More Settings->Field to set->add field->select page  and add matangURL as a value
  • click on Triggering and select matangPageLoad

6 Publish your changes- Submit->Publish and Google Analytics is installed