Try our conversational search powered by Generative AI!

Tracking event on a generic block that is part of a generic page.



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  

Jul 27, 2023 11:13
Chris Sharp - Jul 31, 2023 15:36
Can you provide more info (system/details) on the tracking event? It sounds like you just need to hook into the click event of the button on the client-side and do the tracking through whatever JS script or API call is provided by the tracking system.

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.

Aug 24, 2023 8:26

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.


Edited, Aug 25, 2023 8:14

Thanks a lot for valuable information 

Sep 05, 2023 8:30
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.