railslove / rack-tracker

Tracking made easy: Don’t fool around with adding tracking and analytics partials to your app and concentrate on the things that matter.
https://www.railslove.com/open-source
MIT License
647 stars 121 forks source link

how to set user_id? #145

Closed augustocsmartins closed 4 years ago

augustocsmartins commented 4 years ago

Hi,

I use Devise to Authentication and is not working to set user_id from lambda as the example.

user_id: lambda { |env| env['rack.session']['user_id'] }

Is there another way to setup user_id from current_user or something like it?

iashraf commented 4 years ago

Having the same issue - any ideas?

Edit: I'm sure this isn't great but a possible work around and seems to work fine -

In application_controller.rb -

  before_filter :ga_send_user_id

  def ga_send_user_id
    if user_signed_in?
      tracker do |t|
        t.google_analytics :parameter, { userId: current_user.id }
      end
    end
  end