简体   繁体   English

在 Laravel 5.1 中制作访客跟踪器

[英]Making a visitor tracker in laravel 5.1

I've currently installed a plugin ( https://github.com/antonioribeiro/tracker )我目前安装了一个插件( https://github.com/antonioribeiro/tracker

Which does the tracking thing, only I want to get unique visitors.跟踪的事情,只有我想获得独特的访问者。 I really don't know how to extract those from this package.我真的不知道如何从这个包中提取那些。 Or how I should make one by my own.或者我应该如何自己制作一个。

I want them to return as a JSON object per month.我希望它们每月作为 JSON 对象返回。

If someone could help me out with this?如果有人可以帮我解决这个问题?

I tried it using the tracker_sessions table, but that doesn't work well.我使用tracker_sessions表进行了tracker_sessions ,但效果不佳。

Route::get('admin/api', function(){

        $stats = DB::table('tracker_sessions')
          ->groupBy('created_at')
          ->orderBy('created_at', 'ASC')
          ->get([
            DB::raw('created_at as y'),
            DB::raw('COUNT(*) as b')
          ]);

          return json_encode($stats);
    });

That returns something like this:这将返回如下内容:

[{"y":"2016-05-22 21:17:17","b":1},{"y":"2016-05-22 21:17:27","b":1},{"y":"2016-05-22 21:17:28","b":2},{"y":"2016-05-22 21:17:29","b":1},{"y":"2016-05-22 21:17:31","b":1},{"y":"2016-05-22 21:17:33","b":1},{"y":"2016-05-22 21:18:10","b":1},{"y":"2016-05-22 21:18:11","b":2},{"y":"2016-05-22 21:18:13","b":1}]

Which is not good at all.这一点都不好。

Route::get('admin/api', function(){

    $stats = DB::table('tracker_sessions')
      ->groupBy(DB::raw('CAST(created_at as DATE)'))
      ->orderBy(DB::raw('CAST(created_at as DATE)'))
      ->get([
        DB::raw('CAST(created_at as DATE) as y'),
        DB::raw('COUNT(DISTINCT ip_column) as b')
      ]
    );

    return json_encode($stats);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM