Search code examples
javascriptangularjsgoogle-analyticsmixpanel

How to track if someone clicks a link to leave the page in mixpanel/GA


I am trying to track an event when user tries to leave the website by clicking on a link.

<a ng-click="bookingOutside(trip,0)"  href="https://www.google.com" target="_blank">
          <button type="button" class="externalBooking">
            {{'BOOK'|translate}}
          </button>
        </a>

The bookingOutside event is never fired. Why is this? What can I do about it?


Solution

  • I believe that if you set it up as the event just using this within the link should work, assuming you are using Universal Analytics. To my knowledge it should be in the and not the button format.

    ga('send', 'event', 'button', 'click', 'nav-buttons')

    You can rename some of these to your liking as explained in the link below.

    https://developers.google.com/analytics/devguides/collection/analyticsjs/events