shetabit / visitor

a laravel package to work with visitors and retrieve their informations
MIT License
527 stars 68 forks source link

How can I get online guest count ? #14

Closed codes-zain closed 3 years ago

codes-zain commented 4 years ago

Hi Is it possible to get online visitor or guest users that are not login in ? if is possible how can I do that

weblabio commented 4 years ago

+1 I looked at the source code of the package and came to the conclusion that there is currently no available method that could get the number of guests. So I'm surprised the package does not provide this functionality, or am I wrong?

Since guests are also logged into the visits table, then I see only one way, this is to create my query to the visits table. For example:

\DB::table('visits')
        ->select('id')
        ->where('created_at', '>=', \Carbon\Carbon::now()->subMinutes(3))
        ->whereNull('visitor_id')
        ->groupBy('ip')
        ->get()
        ->count();

Or without groupBy()


\DB::table('visits')
        ->selectRaw('COUNT(DISTINCT(ip)) as count')
        ->where('created_at', '>=', \Carbon\Carbon::now()->subMinutes(3))
        ->whereNull('visitor_id')
        ->get();

But we are faced with a problem, if a user entered the site as a guest and then logged in, then in the statistics there will be 1 online guest and 1 online user, which is not true. image image

And the second problem: the number of guests will be taking into account search robots

CodeNinjaUG commented 3 years ago

hey did u work on the guest visitors problem

khanzadimahdi commented 3 years ago

please add this feature to the package and send a pull request. I will merge it.