tagsgoogle-tag-managerevent-tracking

Want to track click event in GTM when the element doesnt have css class or id


I have a product list filter, I want to track event when someone clicks on different 'view type': list/grid/table, screenshot below: enter image description here

I was able to track click events using Classes and ID's, but these view elements doesnt have any classes or id, instead it has attribute as "data-type", screenshot below:

enter image description here

Can someone explain how can I track event when someone clicks on any of these 3 different view types.


Solution

  • You can use the Click Trigger with condition Click Element

    enter image description here

    So to target the first <a> element you can use the

    CSS Selector : a[data-type='list']

    So the other 2 are quite the same

    a[data-type='grid']

    a[data-type='table']


    Or you want to more precisely by narrow the down the range

    div.change-result-view a[data-type='list']

    This mean you only want the a element with data-type is list under the div.change-result-view