Mixpanel.track from the controller

483 Views Asked by At

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

There are 1 best solutions below

1
On

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.