I solved the issue with the help of an italian developer of a GTM facebook group: https://www.facebook.com/groups/1683981325147575
This is the solution (maybe it can be useful to someone with the same problem).
TO track the open/close as event in GA (Google Analytics) with GTM (Google Tag Manager):
1- go to GTM and create a custom Javascript in the variables:
function() {
var accordion = document.getElementById("{{Click ID}}")
var status = accordion.getAttribute('aria-expanded')
return status;
}
Save as “JS – Open/Close Accordion” (for instance)
2- create a new variable
Type: search table
{{JS – Open/Close Accordion}}
Input:
True–>Open
False–>Close
Save as: Open/Close Accordion (for instance)
3 create a new activator
Activator type: Clic – all elements
Activation by: some clic
Conditions:
Clic classes contains c-accordion__title js-accordion-controller
Page URL coontains [your URL]
Save as “Click on accordion” (for instance)
4- Create a new tag (Universal Analytics)
type: Event
Category: Accordion Click
Action: {{Open/Close Accordion}}
label: {{Click Text}}
Hit from non interaction: False
GA settings: your ga settings
Advanced: tag activation options –> One time per event
Refer to the activator you created on point number 3
5- Test & Deploy