zevarito / mixpanel

Simple lib to track events in Mixpanel service. It can be used in any rack based framework.
MIT License
273 stars 84 forks source link

IP adress not sent ? #81

Closed EtienneDepaulis closed 11 years ago

EtienneDepaulis commented 11 years ago

Hello,

I'm sending various events and setting certain variable but none of those actions seems to send properly the IP adress in order for Mixpanel to geolocate my users.

Here is the code i'm using:

In application_controller:

def mixpanel

  env = {
    'REMOTE_ADDR' => request.env['REMOTE_ADDR'],
    'HTTP_X_FORWARDED_FOR' => request.env['HTTP_X_FORWARDED_FOR'],
    'rack.session' => request.env['rack.session'],
    'mixpanel_events' => request.env['mixpanel_events']
  }

  @mixpanel ||= Mixpanel::Tracker.new ENV['MIXPANEL_API_TOKEN'], { :env => env }

end

then in my registration controller:

mixpanel.track 'New free user', {:distinct_id => current_user.email}
mixpanel.set({distinct_id: current_user.email, ip: request.env['REMOTE_ADDR']}, {created_at: current_user.created_at, email: current_user.email})

Any help on that matter ? Cheers

zevarito commented 11 years ago

Are you deploying in Heroku?

If that is the case, you should use request.env['HTTP_X_FORWARDED_FOR'] instead.

EtienneDepaulis commented 11 years ago

Thanks for this answer, I'm going to try Cheers

EtienneDepaulis commented 11 years ago

Hi @zevarito,

I'm using:

mixpanel.track 'New free user', {:distinct_id => current_user.email, ip: request.env['HTTP_X_FORWARDED_FOR']}
mixpanel.set({distinct_id: current_user.email, ip: request.env['HTTP_X_FORWARDED_FOR']}, {created_at: current_user.created_at, email: current_user.email})

But it's still not working :s Any idea ? Thx

etagwerker commented 11 years ago

@EtienneDepaulis maybe you can try this alternative:

mixpanel.set(distinct_id, {:attribute_1 => 'x', :attribute_2 => 'y'}, { "$ip".to_sym => request.env['HTTP_X_FORWARDED_FOR'] } )

This works for me. Try it!

reconbot commented 11 years ago

@EtienneDepaulis I'm doing it your way and it's working for me

@client.set { distinct_id: user.id, ip: user.ip}, { email: user.email }
scottmessinger commented 11 years ago

I'm also having this same problem. I'm using Heroku. Even when I call mixpanel.set from the console and pass in the right IP address, the location is still set to Ashburn, VA (where Heroku is hosted on AWS).