Add pageview logging via PostHog
This commit is contained in:
parent
3824f01f9b
commit
0f4da7e3df
7 changed files with 114 additions and 14 deletions
28
app/Http/Middleware/PageView.php
Normal file
28
app/Http/Middleware/PageView.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use PostHog\PostHog;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PageView
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
PostHog::capture([
|
||||
'distinctId' => request()->ip(),
|
||||
'event' => '$pageview',
|
||||
'properties' => array(
|
||||
'$current_url' => url()->current(),
|
||||
),
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
|
@ -2,23 +2,27 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use PostHog\PostHog;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
class AppServiceProvider extends ServiceProvider {
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
public function register(): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
public function boot(): void {
|
||||
PostHog::init(
|
||||
Config::get('services.posthog.key'),
|
||||
[
|
||||
'host' => 'https://'.Config::get('services.posthog.host')
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue