Skip to content

Instantly share code, notes, and snippets.

@crystalw
Last active December 19, 2015 03:19
Show Gist options
  • Select an option

  • Save crystalw/5889702 to your computer and use it in GitHub Desktop.

Select an option

Save crystalw/5889702 to your computer and use it in GitHub Desktop.
Check an element's class to determine the outcome of an event and push the occurrence to Google Analytics. Useful for tracking successful form submits on Ajax or other form types with static urls. Google Event Tracking Guide: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
<div class="outcome" class="successful">
<p>Thanks, your message has been sent!</p>
</div>
<script>
$(document).ready(function() {
if ($( '#outcome' ).hasClass( "successful" )) {
_gaq.push(['_trackEvent', 'Category', 'Action', 'opt_label']);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment