Event Name being overwritten

I am encountering the following problem and have no solution so far:

I want to use event tracking based on an onclick event of a hyperlink element. This basically works fine.

The event category and event action are recorded. the event name is fed into this by a file attibute:

function matomoTracking() {
    	_paq = _paq || []; 
    	_paq.push(['trackEvent', 'Button', 'Push','<?php echo $matomo_tracking = $file->getAttribute('matomo_tracking'); ?>']);

Now the Problem I am facing is, that I have multiple of these hyperlink elements on a page and the “matomo_tracking” variable is being overwritten by the last hyperlink element in the list.

This way, the event name will always be the same and defeat the purpose of tracking. Is there any way around this? Somehow to preserve the value?

Ideally, the variable should only be populated IF the hyperlink is being clicked and not just by rendering the page, right?

Thank you for any hints!