Question:
How to send a custom event to Google Analytics 4 using Velo code?
Product:
Studio, WIX Velo
What are you trying to achieve:
I want to send a custom event to GA4 using WIX Velo. For example, if a user clicks on an element, I want to track that event and have it in my GA4 property. I already installed my gtag on my website.
If you need to run arbitrary JavaScript you can use a Custom Element to do so: About Custom Elements You can pass messages back and forth from your page code to the Custom Element as well so then you’ll be able to fire off custom events.
If you’d like Wix to support newer and custom events with trackEvents then submit a feature request on the roadmap: Product Roadmap
I decided to go with Google Tag Manager instead because I was unable to send the events to GA4 using the trackEvent function since it does not allow sending custom properties for events for GA4 (it only supports Universal Analytics properties, like eventCategory, eventAction, eventLabel and eventValue).
For example, I need to be able to send an event on a successful form submission, and send the value of a field as a custom property in the event. I was unable to achieve that with trackEvent for GA4.
While I’m not familiar with different G4A/GTM versions it does seem that in the versions that trackEvent supports according to the docs it’s possible to provide any number of arbitrary properties: