Streaming live at 10am (PST)

How to integrate an OnClick event for analytics

I’m trying to integrate a simple onclick event to help us with the analytics for our site. I’d like to insert the following line of code when a specific button is clicked on our site.

onclick=ga('send','event','Engagement','Click to Subscribe','Fill in Named Value');

Can anyone help me find where I can do this? I’m not a developer and I’ve tried figuring it out through online webflow videos, but have not been able to crack this one. Thanks in advance!

-Ron

2 Likes

The easiest way would be to add some custom code and attach a click handler in there. Give your button a unique ID (like “btn-subscribe” for example) and then add a custom code element to the page. The code could look something like this:

document.getElementById('btn-subscribe').onclick = function () {
  ga('send','event','Engagement','Click to Subscribe','Fill in Named Value');
}

This is assuming it’s just a button… if it’s inside a form, then you’d want to add a unique ID (like “frm-subscribe”) and then add a custom code element to the page. The code could look something like this:

document.getElementById('frm-subscribe').onsubmit = function () {
  ga('send','event','Engagement','Click to Subscribe','Fill in Named Value');
}