Search code examples
google-analyticsmixpanelevent-tracking

Button Click Tracking


In my Django app I've this button when clicked is directed to a google map. I'd like to track this button using Google Analytics and Mixpanel.

  <div id="map-button">
    <a class="active" id="nav" target="_blank" itemprop="hasMap" href="https://www.google.com/maps/place/{{doctor.clinic.geolocation}}"><button id="gmap" class="button"><h5>View on Google Maps</h5></button></a>
  </div>

Solution

  • One possibility is to add a click event listener that fires a GA event whenever a click is registered. You could add the following onclick code to your anchor tag:

    onclick="ga('send', 'event', 'Google maps', 'click');"