Streaming live at 10am (PST)

How to paste GA event tracking codes

Hi, I need to add GA event tracking codes to specific buttons. Apparently they need to be pasted where each link to be tracked is in the body code. Although I can paste into the body code I don’t know how to specifically paste where the actual button is?

Any help would be very much appreciated.

Hi @sparky,

Thanks for the post and good question. Webflow does not support the onclick event for the native links or buttons widgets, however you can create a Click event monitor in jQuery to detect when a link is pressed and run the code that way in the Before Body section of custom code.

It can sometimes be a little complicated to setup the click monitors, what might be easier is to take the full Anchor link code snippet for a link and use a Custom code embed placed on the page where you want the link to appear and then paste in your full link code for a specific link into the embed.

I hope this helps

Thanks very much Dave. This is the site in question

The two links to be tracked are the buttons on the hero section of the home page - Register NOW - UK and Register NOW - International.

Should it work if I simply add two embed codes (which the client has sent to me) into the hero section as follows:-

Register Now UK

onclick="ga(‘send’, ‘event’, { eventCategory: ‘cta’, eventAction: ‘click’, eventLabel: ‘register now uk’, eventValue: 1});”

Register Now International

onclick="ga(‘send’, ‘event’, { eventCategory: ‘cta’, eventAction: ‘click’, eventLabel: ‘register now international’, eventValue: 1});”

I suspect the answer will be that it won’t work as that seems far too easy!