Created
October 12, 2012 20:24
-
-
Save nateberkopec/3881306 to your computer and use it in GitHub Desktop.
Active Tracker API example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of the Active Tracker API | |
# One javascript call at the top of your page can send any events you want to Mixpanel, Kissmetrics, etc | |
# Given a few links like this: | |
# <a href="http://google.com" data-event-name="google" data-event-properties="'target': 'google', 'username': 'nate'"></a> | |
# Then: | |
# active_tracker.track_links(); | |
# ... sends an event called "google" | |
# ... with JSON properties "'target': 'google', 'username': 'nate', 'environment': 'development'" | |
# ... to all of your registered event providers (in this case, mixpanel and kissmetrics) | |
active_tracker.track_links = (selector = '[data-event-name]') -> | |
$.each $(selector), (_, value) -> | |
$value = $(value) | |
properties = $.parseJSON($value.attr("data-event-properties")) or new Object | |
properties.environment = '<%=Rails.env%>' | |
eventName = $value.attr 'data-event-name' | |
mixpanel.track_links selector, eventName, properties |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment