This has nothing to do with Optimizely CMS, imo.
If you are using Google Analytics I would use action trigger as Chris is mentioning; add a click event to the button (inline, or general button event in javascript).
for example;
ga('send','event','Click','Button click','Button/block name');
Since the tracker already know the page (hopefully) you can use the button name which could be returned from the block, in the view.
Throwing in my 50p's worth here.
I agree with Jonas in that this is not Optimizely CMS related and more a Google Tracking issue.
The way I like to do this however is slightly different.
Most sites I have worked with use Google Tag Manager (GTM) to implement Google Analytics (GA).
GTM has more capabilities and allow you to add other javascript functionality to the site for example chat clients, cookie managers, ODP, etc, without need for some developer support.
In order to use GTM for tracking you must then be able to provide GTM with some data, this can be achieve by using data attributes in the markup. Here we are keeping the customised javascript outside the solution and the page will not need to load an additional script on load.
In GTM you can then set up tags to fire when buttons / links are clicked, they will retrieve the data from the data attributes and then pass this to GA.
You can read more about this approach here.
I like this approach as the markup will be standardised and specific for GTM, this way a developer will not interfer with tracking.
Paul
Hi,
We have this requirement of setting tracking click events on the anchor tags.
Just to give example:
We have a CustomTestPage, the instances of CustomeTestPage are used to create different pages (with different URls) on our website. Now each page instance have few blocks on it lets say LinkBlock which contains text and a button, the button links to some other page on our website.
I need to listen to click event on these blocks, and depending on which page they are placed in I have to send different event name to tracking.
How can this be achived ?
Any input would be appreciated