diff options
author | Frankie B <git@diskfloppy.me> | 2024-06-11 21:36:58 +0100 |
---|---|---|
committer | Frankie B <git@diskfloppy.me> | 2024-06-11 21:36:58 +0100 |
commit | e89a7bb329abf3cd252fea7f624acbc454d7caf4 (patch) | |
tree | 20808feb8932992013d25143bc9f4d12fa737b23 /app | |
parent | 210363d17371a699b33a9502bd0f017dca98f915 (diff) |
Add pageview logging via PostHog
Diffstat (limited to 'app')
-rw-r--r-- | app/Http/Middleware/PageView.php | 28 | ||||
-rw-r--r-- | app/Providers/AppServiceProvider.php | 18 |
2 files changed, 39 insertions, 7 deletions
diff --git a/app/Http/Middleware/PageView.php b/app/Http/Middleware/PageView.php new file mode 100644 index 0000000..dda0662 --- /dev/null +++ b/app/Http/Middleware/PageView.php @@ -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); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 452e6b6..3aa155c 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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') + ] + ); } } |