You can use any of the following placeholders in the Category, Action and label fields of any click and scroll event:
|Placeholder||Dynamic data||If missing|
|$$PAGENAME$$||The name of the page where the event was fired|
|$$REFERRER$$||The address of the referrer||meaning the previous page. In case the page had been opened directly||the placeholder will return the URL of the current page.|
|$$ATTR_HREF$$||Link URL||In case that the element is not a link – (not set)|
|$$ELEMENT_TEXT$$||Text wrapped by the element. A button for example.|
|$$AUTHOR$$||Page or post author|
|$$USER$$||Logged in user name||Guest if the visitor is not a logged in user|
|$$ATTR_ID$$||Id of the element. This can be useful if you are tracking multiple elements with the same class||(not set)||Does not work for scroll tracking|
Example – Tracking all the buttons on the site with just one event
As you can see, by tracking all clicks on every element with the “btn” class, we can track all the buttons on the website. Each event will include the page name as the category and the button text as the label.
Advanced Placeholders – $$ATTR_$$
There is also a special placeholder that allows you to include any attribute of an HTML element in the event data.
Anything you add after the $$ATTR_ can represent an HTML attribute of the clicked element.
For example, use $$ATTR_HREF$$ to grab a link’s href attribute (the link).
Or use $$ATTR_SRC$$ for an image file source.
Advanced placeholder use case
We have a page with four buttons, each one does a different action when you click it.
Here is how the HTML of the page looks like:
We can track them all with one click event, by using the btn-action class. But how can we differentiate between them?
You can see that each button has the data-action attribute, which tells us something unique about the button.
The placeholder we will use is $$ATTR_DATA-ACTION$$
Click Event Settings
The result on Google Analytics