Sorry to resurrect, but here is an (untested) solution that should work. You can specify the event name using the data-track
property, and any additional event attributes using a JSON string in the data-track-attrs
property. The javascript will bind to the click handler for any element with a data-track
property and dispatch the event to Mixpanel. In the case where a native JSON decoder is not available, it will fail silently.
<div class="header">
<a href="#" data-track="Login" data-track-attrs='{ "where": "header" }'>login</a>
</div>
<a href="#" data-track="Open slideshow" data-track-attrs="{ show: 'Xmas' }">open xmas</a>
<div class="footer">
<a href="#" data-track="Login" data-track-attrs='{ "where": "footer" }'>login</a>
</div>
<script type="text/javascript">
$(function() {
$("body").on('click', '[data-track]', function(evt) {
var event_name = $(this).data('track');
var event_attrs;
try {
event_attrs = JSON.parse($(this).data('track-attrs'));
} catch(e) {}
mixpanel.track(event_name, event_attrs);
});
});