October 2017
Intermediate to advanced
370 pages
8h 57m
English
It's often useful to track what a user has clicked or tapped on. We can target elements to track using CSS selector style syntax. For example, suppose we had a simple button in our page like this:
<button>Click me!</button>
Then we could track its clicks with the following (/ch10/ga-click-button.html):
{ "vars": { "account": "UA-XXXXXXXX-X" }, "triggers": { "buttonClickTracker": { "on": "click", "selector": "button", "request": "event", "vars": { "eventCategory": "Click tracking", "eventAction": "click button", "eventLabel": "Click me button", } } }}
Note the variables eventCategory, eventAction, and eventLabel. We can add any variables we want here, but these particular ones are supported in the event request type ...
Read now
Unlock full access