I’m not sure if anything has changed here in the meantime, but I would like to add an onclick event to a link to implement Google Tag Manager conversion tracking.
I could be wrong but the code you are showing looks more like UA code. GA4 has changed things, where an event is more generic and has more parts. GTM is totally different again.
I usually use GTM. With GTM you’d do something like put an ID or class or custom attribute on the link, and then setup the click handler in GTM.
Your approach or something similar could work if you want to go straight to GA4, and yes you could use a custom element to support your onclick attribute.
But I do think the code has changed a bit for GA4 events.