Mixpanel.track from the controller

北城余情 提交于 2020-01-02 21:48:42

问题


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:

  1. Add analytical to your controller
  2. 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:
    
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!