Google Analytics Event Tracking in Google Tag Manager

I'm relatively new to tracking analytics events, etc.

I'm just wondering what is the Google Tag Manager equivalent to Google Analytics ( onchange="ga('send', 'event', 'Category', 'Change', 'Value');")?

I know that I can use onlayer, but I'm not 100% sure how to use it, tried to find several articles online, but nothing that could help me.

Basically, I have a stylized element selectthat I want to track when it changes its meaning. There is no submit button and it is not inside the form element.

Google Tag Manager only allows me to click, which returns incorrect values, because its select element requires onchange, not onclick.

My question is: can I use the Google Analytics event tracking code inside the Google Tag Manager, if that makes sense? My Google Analytics is added through Google Tag Manager, so it's tracking.

Your answer is welcome, thanks

+4
source share
3 answers

, HTML, , onchange select. dataLayer, . UA, , , .

, :

  • HTML- , DOM , select:

    <script>
      $('#myselect').on('change', function(){
        dataLayer.push({
          'event':'select_change',
          'select_val':this.value
        });
      });
    </script>
    
  • custom event, = select_change

  • Universal Analytics, , (, , , ). , -
    • category =
    • =
    • label = {{select_val}}

shoudl , 2.

+4

" ", Simo Ahava. , .

, GTM GA, , . , dataLayer, GA.

dataLayer.push({
  'event' : 'GAEvent',
  'eventCategory' : value_for_Event_Category,
  'eventAction' : value_for_Event_Action,
  'eventLabel' : value_for_Event_Label,
  'eventValue' : value_for_Event_Value
});

, , , dataLayer . , , , (Simo "GAEvent" ). , GA. , , , dataLayer. , , . GTM .

: . , , "undefined". , , , , .

+2

, HTML, > , onchange select. > dataLayer, > . UA, > , > .

, :

1. HTML- , > DOM, , select:

<script>
 $('#myselect').on('change', function(){
   dataLayer.push({
     'event':'select_change',
     'select_val':this.value
   });
 });

2. , = select_change
   3. Universal Analytics, , > (, , , ). , -

       -category =
       -action =
       -label = {{select_val}}

shoudl , 2.

, dmpg_tom .

, 1,2,3,4 .., . this.Text this.HTML .

I edited the code as follows using here :

<script>
 $('#myselect').on('change', function(){

var mySelect = document.getElementById("myselect");
var selectedText = mySelect.options[mySelect.selectedIndex].text;

  dataLayer.push({
  'event':'select_change',
  'select_val':selectedText
});
});
</script>

In this example, it will now return "Hello" instead of "1".
       <option value="1">Hello</option>

0
source

Source: https://habr.com/ru/post/1615045/


All Articles