Correct syntax for event tracking in Google Analytics 2015

im new when implementing event tracking in analytics, this is a contact form and i would like to know if my syntax is correct, google analytics help is not very reasonable. I am using the jQuery example they provide.

<button type="submit" class="btn btn-xl-contacto">Escríbenos</button>
<script>
$('#btn btn-xl-contacto').on('click', function() {
ga('send', 'event', 'button', 'click', 'boton-contacto');
});
</script>

      

+3


source to share


2 answers


Yes, that's right.



When in doubt, you can always just try to see if it works. Using the analytics_debug.js script is great for this. This allows you to view the web console and see exactly what is going on.

0


source


Fixed!

i used and id instead of class when calling script:

<button type="submit" class="btn btn-xl-contacto">Escríbenos</button>
<script>
$('.btn-xl-contacto').on('click', function() {
ga('send', 'event', 'button', 'click', 'boton-contacto');
});
</script>

      



changed '#' for '.' and only used the last class attribute (in this case btn-xl-contacto).

Everything works fine now.

0


source







All Articles