When there is neither a class nor an id…
Sometimes you come across buttons on pages that you really, really need to add click tracking to via Google Tag Manager, but it is impossible to identify them by class or id.
This is exactly the kind of stylish button I ran into recently:
![]()
with simple code:
<a class="btn btn-default btn-xs wc white tabsdostavka" href="#tabs_section">
<i class="fa fa-truck"></i>
<span>Стоимость доставки</span
</a>
It would seem that it has the class “btn btn-default btn-xs wc white tabsdostavka”, and you could calmly create a trigger in Google Tag Manager like:

But such a trigger did not work. I turned to the debugger to figure out which value for the class was the correct one. And the debugger showed that all the variables were empty, and Click Element contained the not-very-informative value “[object HTMLSpanElement]”:

And yet, this problem is solved simply, without involving a programmer!
The built-in GTM variable “Click Text” comes to the rescue - that is what you need to set up the trigger on. In my case it should equal “Стоимость доставки”, and the trigger will look like this:

You also need to account for clicks on the icon inside the button, which is already calmly identified by the class “fa fa-truck”. The trigger for the icon:

And let’s hope that the same icon or the same text will not be used on other elements of the site. Unfortunately, neither the use of class nor id can give us such a guarantee, so we will consider the solution satisfactory.