I wrote up a fairly lengthy article on how to use Mixpanel with Ruby on Rails. Mixpanel is a new analytics service I’ve been playing around with for the last week or so. It is probably slightly more technically involved than most uISVs would care for, but the funnel tracking is solid gold. You can see some changes that lead me to making for BCC, too.
As always, I’d love to hear your comments. (I am on a bit of an optimization kick lately, aren’t I. Got to get ready for the school year! Three more weeks or so and I won’t be able to break the website NEARLY so often.)
Excellent Patrick, and at least for me perfect timing!
Thanks for this. Just wanted to let you know that this code has a minor bug in it that only started breaking in the last couple of days.
In the Mixpanel object, you are using http.post to make the post request. This method does not include a Content-length header apparently. Switching to http.request_post fixed the issue.
Thanks for your report Rob.
While it appears to work fine with request_post, I think the issue you were seeing was probably caused by posting with a nil data URL rather than posting with http.post. Here’s the minimum test case to reproduce this:
res = Net::HTTP.start(“api.mixpanel.com”, 80) do |http|
http.post(“/track/”, nil)
end
You’ll get the 411 error. Change request_post to regular old post, you’ll still get the 411 error. change the nil to a proper value, no error for either one.
Hi Patrick, thanks for your review on Mixpanel. It has been helpful for since I am researching a good analytic suite for a joint-project app.
I have a question. Say, I wanna track all the URLs that lead to the Signup page, internally and externally. So we can identify which page/site is doing the best job, and make decision on that.
Where do I do that in Mixpanel? Or, based on your experience with other web analytics package, what service do that best?
I’m looking forward to your reply, thank you :)
Patrick-
Thanks for the article and code but I dont believe it is working correctly with DJ, at least not the collective-idea fork, which is basically the same.
Basically when I look at the DJ log I see this for each entry your script adds as the error:
“undefined method `access_api!’ for #…”
In the script you have access_api! defined as a method but not self.access_api!, which might be causing the issue.
Not sure what you are seeing on your end or what version of DJ you wrote this with but would appreciate any feedback.
Best,
Josh
Thanks for the comment Josh. You are having difficulties because of the JSON library you have loaded — it is not happy with serializing a method name with a bang (exclamation point) in it.
If you rename the access_api! method to access_api in all places, it will work fine.