We deal with a lot of Wix websites. They can be very powerful with the Corvid development platform. But they can also make you pull your hair out. I spent a few hours last week working on an issue for a client. We needed to tie a Google event code to a button that also was hyperlinked to an external site.
First stop was to the Wix Help Center. Found this article (Corvid: Reacting to User Actions Using Events) so we could add an event handler for the button. Then we found “Corvid Tutorial: Sending Tracking and Analytics Events“. Great articles we were well on our way. By following the articles we got the event code to work with the button. But we found out that after the code is tied to the button the hyperlink no longer works! What is up with that? We looked in the Covid Forum and found the following article OnClick event and linking a button not possible? (solved). Apparently if you hyperlink the button in the GUI Wix editor it no longer works if you tie an event to it. But we were on the right track. We needed to use the wix.location.to code to make this work. When we first tried it, the event worked and the hyperlink worked but it did not open the external website in another tab. So back to the drawing board. Wix also has code for a button function that is $w(“#yourbutton”).link and $w(“#yourbutton”).target. So we combined the button export function code, the wixLocation.to code, and the button function codes and it worked!
With all of the people that we ran across in the Corvid forums, and in Stack Overflow, that had the same issue, I wonder why the complete fix is not posted on the Wix site. Here is the full code below that worked.
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’
$w.onReady(function () {
$w(“#yourwix element name”).link = “”;
$w(“#yourwix element name”).target = “_blank”;
});
export function yourwix element name(event) {
wixWindow.trackEvent(“CustomEvent”, {
“event”: “Your Google Event Name”,
“eventCategory”: “Your Google Category Name”,
“eventAction”: “Your Google Action Name”,
“eventLabel”: “Your Google Label”
//Add your code for this event here:
});
wixLocation.to(‘https://YourExternalWebsiteURL’)
}
If you need any help with your Wix website or Google Analytics Events and Goals let us know we would be glad to help.