I have a problem counting account in Mixpanel for my Rails application. Basically, I fire the mixpanel "Session" tracking event every time someone visits a page from an external URL (not mydomain.com).
So, I have something like this in my application_controller.rb application before hook:
def count_session referral = request.referer root_url = Figaro.env.root_uri ### If there a referral and it includes the root domain, then don't ### track because it the same session if referral && referral.include?(root_url) puts "!!!! NOT TRACKED !!!!!" else puts "!!!!! TRACKED #{id} !!!!!!" mixpanel.track("Session", "ID" => current_user.id, "Version" => Figaro.env.ab_version ) end end
For debugging, I can see "!!!!! TRACKED 4 !!!!!!" in my console when visiting a page from my account (user ID: 4). But when I am in MixPanel, the event does not appear on the toolbar.
I can get a session event for logging in if I visit incognito in the browser (with id: nil) OR if I am incognito, and then explicitly log in to my account. But the goal is to log an event anytime a user visits an external URL.
My other mixpanel events are working fine. Any idea why the session event will not fire in this case? How should I continue this debugging?
Thanks!
Edit: I am using Mengpaneel to implement ruby, here is my setup:
Initializers / mengpaneel.rb:
Mengpaneel.configure do |config| config.token = Figaro.env.mixpanel_token end
application_controller.rb:
before_action :setup_mixpanel before_action :count_session def setup_mixpanel return unless user_signed_in? mengpaneel.setup do mixpanel.identify(current_user.id) mixpanel.people.set( "ID" => current_user.id, "$email" => current_user.email, "$created" => current_user.created_at, "$last_login" => current_user.current_sign_in_at ) end end
ruby-on-rails mixpanel
Jackson cunningham
source share