0

I would like to add analytics.js click tracking to some elements on a page which all have a unique data- attribute.

On the anaytics page :

https://developers.google.com/analytics/devguides/collection/analyticsjs/events

It says to add the code in the following format :

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

Although when for instance it says eventCategory the example it gives is just "Video" rather than a class or id.

My question is how would i right the above so it tracks each element based on its data attribute for instance : data-id="2250ee774b0a42688745b6143b662328"

Any help would be greatly appreciated.

Thanks

David

  • so you are asking how to extract data properties from clicked element? – Kasia Jan 23 '17 at 16:43
  • I basically just want to know whos clicked on elements and use the data-property like a id to track, so on anayltics have a list saying data-1 clicked...... or data-2 clicked....... – David_George Jan 23 '17 at 17:17

2 Answers2

0

you should use https://sizzlejs.com/ to find the selector based on data-id and write custom code.

But why not use this tool to record your actions without going through this hassle.

www.customerlabs.co checkout their action recorder.

Vishnu Vankayala
  • 129
  • 1
  • 3
  • 15
0

It depends on how you want to see the data in the google analytics and what are those "some elements", I would suggest using the following approach using jQuery by adding a click handler

Suppose you want to group all the data-id under a category DataIDClicks

$('[data-id]').on("click",function(){
  ga('send', 'event', 'DataIDClicks', $(this).data('id'));
})
Nadeem Manzoor
  • 760
  • 5
  • 14