Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Understanding gtag parameters and addressing issues with page URL and button text › Reply To: Understanding gtag parameters and addressing issues with page URL and button text
-
In the place of ‘page_url’, you need to pass the current page URL in the form of a string. Right now, what it seems like you’re doing is passing a string literal ‘page_url’ instead of the actual page URL. You could use ‘location.href’ to get the URL of the current page. It would look something like this: ‘page_url’ : location.href.
As for the ‘button_text’, this should be the text that the button users click on is displaying. If you’re placing ‘button_text’ as a string, it will only display as just that – ‘button_text’. However, you likely want it to reflect the actual text. So you need to configure it to grab that, like this: ‘button_text’ : document.getElementById(“button-id”).innerText, assuming you have a button with the id of “button-id”.
Therefore, your gtag should look something like this:
`
gtag(‘event’, ‘CTA Click’, {
‘page_url’ : location.href,
‘button_text’ : document.getElementById(“button-id”).innerText,
‘event_label’ : ‘CTA Clicks’
});
`
This should solve your issue. The ‘page_url’ will then contain the actual URL of the page where the event is happening, and ‘button_text’ will show the actual text that exists on the button. ‘event_label’ can remain as ‘CTA Clicks’. Be sure to replace “button-id” with your actual button’s ID. If the text isn’t changing, make sure that the ID correctly corresponds to the button that’s being clicked.