tracker icon indicating copy to clipboard operation
tracker copied to clipboard

Trackers Session : user_id is null

Open piep14 opened this issue 4 years ago • 12 comments

Hello,

I am under Laravel 6 and since the last update of the Package, in "tracker_sessions", the value of "user_id" is always null.

Would it be possible to correct this bug?

Thank you in advance.

piep14 avatar Jan 27 '20 09:01 piep14

@antonioribeiro ^^

piep14 avatar Feb 06 '20 07:02 piep14

Hi. Vendor/Laravel/ServiceProvider.php

` public function boot() { parent::boot();

    if (!$this->getConfig('enabled')) {
        return false;
    }

    $this->loadRoutes();

    $this->registerErrorHandler();

    // $this->bootTracker();

    $this->loadTranslations();
}`

You can just comment this line out ($this->bootTracker();) in the package Service Provider boot method.

kazemimorteza68 avatar Feb 09 '20 06:02 kazemimorteza68

https://github.com/antonioribeiro/tracker/issues/479

kazemimorteza68 avatar Feb 09 '20 07:02 kazemimorteza68

I edited the package directly in the FTP, then commented the line as you suggest. But it still doesn't work. Are there a few more things to do?

piep14 avatar Feb 17 '20 08:02 piep14

@kazemimorteza68 @antonioribeiro

Can you help me ?

piep14 avatar Feb 28 '20 07:02 piep14

I have the same error! Configured everything properly but still doesn't work. Using Laravel 6.18

hopingsteam avatar Mar 15 '20 15:03 hopingsteam

I have a problem when the user login at the website, and doesn't save user-id at the table tracker_sessions. it is always null. please help me and give me a solution.

HamidNiakan avatar Apr 05 '20 17:04 HamidNiakan

My solution was in the Login controller: It's not cute but it works hahaha.

$visitor = \Tracker::currentSession(); if($visitor) { $visitor->user_id= Auth::user()->id; $visitor->save(); }

calazcano avatar Apr 08 '20 18:04 calazcano

I figured this out after following through the code. There are three crucial steps that must be followed .

  1. ensure that the correct auth guard is set in config/auth.php this usually is set to web and the provider model is App\User::class in fresh installations . If your application is using a different auth gaurd and path for model it may work fine but missing user_id on saved data in this package may be sign of a miss-configured auth guard
  2. With this done now you need to set the guard in (1 ) in config/tracker.php on the authentication_guards key for example

'authentication_guards' => ['web'] 3) in Vendor/Laravel/ServiceProvider.php comment out $this->bootTracker(); If this is done the package should now pick up the user_id

stephenmudere avatar Apr 09 '20 18:04 stephenmudere

I made a PR to solve this issue

https://github.com/antonioribeiro/tracker/pull/514

vinkev avatar Sep 23 '20 03:09 vinkev

calazcano commented on 9 Apr 2020 -> Excellent!! It's working fine.

suntaehong avatar Jan 13 '21 14:01 suntaehong

$visitor = \Tracker::currentSession();

it works, Thanks

saqlain-syed avatar Feb 04 '22 09:02 saqlain-syed