无法在rails中跟踪会话

时间:2016-02-24 20:00:11

标签: ruby-on-rails mixpanel

我在使用Mixpanel为我的Rails应用计算会话时遇到问题。基本上,我正在开设一个" Session"每当有人从外部网址(而不是mydomain.com)访问网页时,都会进行混合面板跟踪事件。

所以我在我的application_controller.rb中有这样的东西,之后是hook:

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

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

如果我在隐身浏览器中访问(ID为nil),我可以记录会话事件。如果我访问隐身,则显式登录到我的帐户。但目标是在用户从外部网址访问时随时注册事件。

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

谢谢!

修改:我使用Mengpaneel进行ruby实施,这是我的设置:

初​​始化/ 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

1 个答案:

答案 0 :(得分:0)

  

知道为什么会话事件不会在这个实例中触发?我该如何进一步调试呢?

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

随处添加日志记录!在mengpaneel的跟踪方法中:

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

  properties = @properties.merge(properties)

  super(@distinct_id, event, properties)
end

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

我知道你说其他电话正在工作,所以也许只是这个电话会被悄悄地掉线。

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