Extract text from an element

Hi… I want to create a report that lists all clicks on CTA buttons that have class=button.

I have created a variable called “Button text” where Extract text from an element is turned on.

I use {{ Button text }} in a Custom event, but in the report, I get all the buttons on the page that have the class button. So I can’t know witch button was clicked on.

Does anyone know what I need to do so that it ONLY outputs the name of the button that is clicked, and not all the buttons with the same class?

As you can see in my report, I have 3 buttons on the page: “2x Free trial and dive deeper

Thank you very much in advance for all the input.

Hi Thomas,

Piwik PRO has a built in variable called {{ Click Element }} - you could use it to refer only to the specific button that was clicked. It returns the whole element, so you would need to extract the text inside first :slight_smile:

For that you can use a custom JS variable, or do it in the tag itself, depends on your preference and the structure of the buttons.

Thank you … created a Custom JS that just output the inner text element.

1 Like