How to use the Clicked HTML Attribute variable
In Matomo Tag Manager, the Clicked HTML Attribute variable allows you to capture the value of a standard HTML attribute (e.g., id, class, href, alt, title ) from an element that users click on. This is useful for dynamically tracking interactions without hardcoding values or creating custom scripts for each interaction.
This guide explains how to track clicks on images and capture the image’s alt
text.
Configure the Clicked HTML Attribute variable
- In Tag Manager, navigate to Variables and click Create New Variable.
- Select the Clicked HTML Attribute Variable and provide a descriptive name.
- In the Clicked HTML Attribute Name field, specify the attribute name you want to capture. Using the example, enter
alt
. - Save the new variable. It can now be used to fire a trigger and execute a tag.
Set up a Click Trigger
- Navigate to Triggers and click Create New Trigger.
- Select the All Elements Click Trigger and provide a descriptive name.
- Add a condition to fire the trigger only when elements with the
alt
attribute are clicked. - Choose the Click HTML Attribute created previously and specify the condition matches the regular expression
^(?!\s*$)[^x].+
- Save the new trigger.
Set up the Matomo Analytics Tag
- Navigate to Tags and click Create New Tag.
- Select the Matomo Analytics Tag and provide a descriptive name.
- Choose the Event Tracking Type and (using the example above), define the event as you want it to appear in your reports:
Event Category: Images
Event Action: Clicked
Event Name: select the variable created previously{{Clicked HTML Attribute - alt}}
.
- Link the All Elements Click Trigger.
- Save the new tag.
- Use Preview and Debug mode to test your setup before publishing.
- Once successfully configured, run a test event and check it is recorded in the Matomo Real-time report.