问题
I have an application that has a simple form submission (an email). I have MixPanel's tracking analytics integrated into the app, and want to track every time an interaction with this form happens--specifically, when a user successfully/unsuccessfully submits the form, and what their email is.
After doing some research, it seems simplest method is to track at the controller level (where I am running validations, and making the overall decision whether or not the submission is legitimate). This would require running a JS function from the controller. Is this possible? Is there a better method of doing this?
回答1:
Let integrate this gem analytical.
Then just follow the instruction in above link, but here is the summary:
- Add
analytical
to your controller Setup mixpanel token in
config/analytical.yml
production: mixpanel: key: your_mixpanel_project_token development: # Also define here if you want to test in development test:
Track your event in controller:
# data_key_1, data_value_1, data_key_2 and data_value_2 are the data # which were attached to mixpanel event, they are example, specify yours analytical.event 'Your event', data_key_1: data_value_1, data_key_2: data_value_2
You may integrate more with GA, KISSMetrics, or whatever you want, the tracking code works in generic, this also works with javascript code, for more detail, please refer its documentation.
来源:https://stackoverflow.com/questions/35122695/mixpanel-track-from-the-controller