# How can Button open link in new tab \*and\* send tracking event?

**URL:** <https://forum.wixstudio.com/t/how-can-button-open-link-in-new-tab-and-send-tracking-event/21861>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 17, 2020, 11:04pm UTC](https://forum.wixstudio.com/t/how-can-button-open-link-in-new-tab-and-send-tracking-event/21861 "2020-05-17T23:04:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jharuni](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jharuni](https://forum.wixstudio.com/u/jharuni)\
**Post date:** [May 17, 2020, 11:04pm UTC](https://forum.wixstudio.com/t/how-can-button-open-link-in-new-tab-and-send-tracking-event/21861/1 "2020-05-17T23:04:45Z")

</div>

A button has a link which can be set to open in a new window/tab. I also want to send a tracking event so I add an onClick() to do it, and that works but then the link no longer works. I’m sure there was a time when I could have both, but ok … there is documentation saying I shouldn’t have a link and an onclick handler so I won’t do that.

There is also documentation saying I can use wix-location.to() in the handler instead of the button’s regular link function. That does work, but it won’t open in a new tab, as noted in other discussions in this forum.

How can I open a button’s link in a new tab and also send a tracking event?

FYI I noticed wix-window.openModal(). That works but not the UX I want. I need something like javascript’s window.open() … is there a way I can call that from Corvid?

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [May 18, 2020, 1:22am UTC](https://forum.wixstudio.com/t/how-can-button-open-link-in-new-tab-and-send-tracking-event/21861/2 "2020-05-18T01:22:10Z")

</div>

There are example pages that you can read about it here.  
[https://support.wix.com/en/article/corvid-tutorial-sending-tracking-and-analytics-events](https://support.wix.com/en/article/corvid-tutorial-sending-tracking-and-analytics-events)  
[https://support.wix.com/en/article/tracking-click-events-with-google-tag-manager](https://support.wix.com/en/article/tracking-click-events-with-google-tag-manager)

Also, if Wix Location API and the to() function is not suitable for you, then have a look at using target and link instead.  
[https://www.wix.com/corvid/reference/wix-location.html#to](https://www.wix.com/corvid/reference/wix-location.html#to)  
[https://www.wix.com/corvid/reference/$w.LinkableMixin.html](https://www.wix.com/corvid/reference/$w.LinkableMixin.html)

---

<div class="post-metadata">

**Author:** ![jharuni](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jharuni](https://forum.wixstudio.com/u/jharuni)\
**Post date:** [May 18, 2020, 1:34am UTC](https://forum.wixstudio.com/t/how-can-button-open-link-in-new-tab-and-send-tracking-event/21861/3 "2020-05-18T01:34:32Z")

</div>

@GOS your second link might be useful, I have been thinking of using GTM and it looks like doing that would mean not needing a click handler, so I might just work around this problem. But meanwhile, I ought to be able to get this working with just GA Event posting, and solve this problem rather than doing something else entirely.

Your first link is just documentation about how to send tracking events, but I already have that working in isolation. Your last couple of links about LinkableMixins, I already looked at that. Several other threads in this forum conclude that it doesn’t work in onClick() handlers. So I’m not tempted to try it. Do you know that this would work in onClick() ?

Thank you
