Rails Tracking Issue

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 
+8
ruby-on-rails mixpanel
source share
1 answer

Any idea why the session event will not fire in this case? How should I continue this debugging?

To answer the question about debugging your question, I would start by saying that I sent this event correctly.

Add all the info! In the mengpaneel track method:

 def track(event, properties = {}) return if @disable_all_events || @disabled_events.include?(event) properties = @properties.merge(properties) super(@distinct_id, event, properties) end 

I would check what @disable_all_events and @disabled_events are set for by updating my local gem to register these attributes. I also log the result of calling super if it returns some kind of error response. Or using ruby debugger .

I know that you said that other calls work, so maybe this is just that call that is falling quietly.

Another option is to figure out how to get a proxy server in the middle of HTTP requests (i.e. Charles).

0
source share

All Articles