Actually it seems to work but my onclick() event is supposed to trigger a Matomo function named _paq.push() that awaits for 3 values, not just one.
Thanks to ChatGPT, i found a solution to inject the 3 values in _paq.push() via data attributes set into the <a> tag (given L&L doesn’t parse its dynamic tags in onclick).
<Set template="post_tracking" type="string"><Get post_type_label />,<Field acf_radio=entrenous_type field=label />,<Field title /></Set>
<a href="{Get template=post_url}"
data-category="{Get post_type_label}"
data-action="{Field acf_radio=entrenous_type field=label}"
data-name="{Field title}"
onclick="trackEvent(this)">My link</a>
<script>
function trackEvent(element) {
// Get the dynamic values from the data-* attributes
var category = element.dataset.category;
var action = element.dataset.action;
var name = element.dataset.name;
// Log the values for debugging
console.log('Category:', category);
console.log('Action:', action);
console.log('Name:', name);
// Ensure _paq is defined and the required values are present
if (typeof _paq !== 'undefined' && category && action && name) {
_paq.push(['trackEvent', category, action, name]);
} else {
console.error('Tracking object (_paq) not defined or missing parameters.');
}
}
</script>
Note: i wasn’t able to use the L&L Script tab and inserted the JS function directly into the Template instead.
i’d like to understand how to use the Script tab and why it might be a better approach.