GA Events breaking links

I have started implementing GA events on elements of my site. They are all working fine, except for when I add the event tracking to a button that links to a new page.

In these cases the GA event tracking breaks the link, so the button does not work.

I’m assuming there is some interference between the code I’ve added to the onClick event and the built in functionality to open the next page. Or is it possible simply having an onClick event created via the properties window breaks the link functionality of a button?

Any advice? Maybe a way to add code to the export function of the onClick to fire the link after the GA event has fired? I tried to use location.href but couldn’t get it to work (I’m a newbie, code is below). I’m hoping there is a simpler solution.

export function Orderbutton1_click(event) {
wixWindow.trackEvent("CustomEvent", {
"event":"Ordervideomappage",
"eventCategory":"ordervideobuttonmappage",
"eventAction": "ordervideoclick",
});
location.href = "http://asmrvideocentral.com/order-personalized-video";
}

Hi,
When adding both link and onClick event for the same element, only the code within an onClick event runs.

To resolve the issue, you can set your link using Wix Location API inside the onClick event. Click here to learn more.

As Wix Location API can’t open a link in a new tab, if you need to do it, you can use the following workaround:
This can be achieved by adding a new box element to the page, adding onClick to the box and then putting a button with a link into the box. This way box will catch the event, so you can run your code and the link will open.