Tautvydas Slegaitis Tautvydas Slegaitis - 1 year ago 72
Javascript Question

Google Analytics Event Tracking in Google Tag Manager

I'm relatively new to Analytics Event tracking etc.

I'm just wondering what is Google Tag Manager equivalent to Google Analytics (

onchange="ga('send', 'event', 'Category', 'Change', 'Value');"
) ?

I know I can use onlayer but I'm not 100% sure on how to do use it, tried looking up online few articles but nothing that could help me.

Basically what I have is a styled
element that I want to track when it changes its value. There is no submit button and its not inside a form element.

Google Tag Manager only let me do on click which returns wrong values because its a select element and needs onchange rather than onclick.

My question is can I use Google Analytics Event Tracking code inside Google Tag Manager if that makes sense? My Google Analytics are inserted through Google Tag Manager, so is tracking.

Your reply is appreciated, thanks

Answer Source

If I were implementing this I would create a custom HTML tag containing a function that binds to the onchange event fo your select element. The function would fire a custom event into the dataLayer which also contains pertinent information. You would then create a UA event tracking tag that uses the correct information and is fired by a custom trigger that is fired by the custom event name.

So, as follows:

  1. Create Custom HTML tag with some similar functionality to this, fire it on DOM ready of all pages you want to bind to a select element:

      $('#myselect').on('change', function(){
  2. Create a trigger of type custom event where event value = select_change

  3. Create a Universal Analytics tag which is an event tag and fill in the the required details (category, action, label, value). If this was me I'd use something like
    • category = user interaction
    • action = select change
    • label = {{select_val}}

This tag shoudl be fired by the trigger you created in 2.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download