无法在rails中跟踪会话

Jac*_*ham 8 ruby-on-rails mixpanel

我在使用Mixpanel为我的Rails应用程序计算会话时遇到问题.基本上,每当有人从外部URL(而不是mydomain.com)访问页面时,我就会触发"会话"混合面板跟踪事件.

所以我在我的application_controller.rb中有这样的东西在钩子之前:

def count_session
    referral = request.referer
    root_url = Figaro.env.root_uri

    ### If there's a referral and it includes the root domain, then don't 
    ### track because it's 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
Run Code Online (Sandbox Code Playgroud)

为了调试,我能看到"!!!!! TRACKED 4 !!!!!!" 在我的控制台中从我的帐户访问该页面时(用户ID:4).但是当我访问MixPanel时,仪表板中没有显示任何事件.

如果我在隐身浏览器中访问(ID为nil),或者如果我访问隐身,然后明确登录到我的帐户,我可以记录会话事件.但目标是在用户从外部URL访问时随时注册事件.

我的其他mixpanel活动正常.知道为什么会话事件不会在这个实例中触发?我该如何进一步调试呢?

谢谢!

编辑:我正在使用Mengpaneel进行ruby实现,这是我的设置:

初始化/ mengpaneel.rb:

Mengpaneel.configure do |config|
  config.token = Figaro.env.mixpanel_token
end
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

Nic*_*olm 0

知道为什么在这种情况下会话事件不会被触发吗?我应该如何进一步调试这个?

为了回答您问题的调试方面,我首先要确保以正确的方式发送此事件。

到处添加日志记录!在mengpaneel的track方法中:

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

  properties = @properties.merge(properties)

  super(@distinct_id, event, properties)
end
Run Code Online (Sandbox Code Playgroud)

我会通过更新本地 gem 来记录这些属性来检查@disable_all_events和 的设置。@disabled_events我还会记录调用的结果super,以防它返回某种错误响应。或者使用红宝石debugger

我知道您说过其他呼叫正在工作,所以也许只是这个呼叫被默默地挂断了。

另一种选择是弄清楚如何在 HTTP 请求中间获取代理(即 Charles)。