From b04fba495564ae8894f57d1b65226cfc9165a3f7 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Sun, 25 Oct 2015 11:11:13 -0700 Subject: [PATCH] Fix incorrect array for mixpanel data, fix reference to user primary key --- CHANGELOG.md | 6 ++++++ src/Listeners/LaravelMixpanelEventHandler.php | 15 ++++++++------- src/Listeners/LaravelMixpanelUserObserver.php | 15 +++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3673410..9026677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). (This is already detected in subscription update.) - Filter any incoming webhook events that are in test mode. +## [0.4.7] - 25 Oct 2015 +### Fixed +- improper tracking of user details, which caused users' names to be blank and a `0 Object [object]` field to be tracked + erroneously. +- fixed tracking to not depend on `$user->id` when referencing the primary key, but pulling it dynamically instead. + ## [0.4.6] - 25 Sep 2015 ### Fixed - documentation references to old Mixpanel class. diff --git a/src/Listeners/LaravelMixpanelEventHandler.php b/src/Listeners/LaravelMixpanelEventHandler.php index 828050c..c33b704 100644 --- a/src/Listeners/LaravelMixpanelEventHandler.php +++ b/src/Listeners/LaravelMixpanelEventHandler.php @@ -37,7 +37,7 @@ public function onUserLoginAttempt(array $event) if ($user && ! $this->guard->getProvider()->validateCredentials($user, ['email' => $email, 'password' => $password]) ) { - $this->mixPanel->identify($user->id); + $this->mixPanel->identify($user->getKey()); $this->mixPanel->track('Session', ['Status' => 'Login Failed']); } } @@ -57,7 +57,7 @@ public function onUserLogin(Model $user) $firstName = implode(' ', $nameParts); } - $data[] = [ + $data = [ '$first_name' => $firstName, '$last_name' => $lastName, '$email' => $user->email, @@ -69,9 +69,9 @@ public function onUserLogin(Model $user) array_filter($data); - $this->mixPanel->identify($user->id); + $this->mixPanel->identify($user->getKey()); $request = App::make(Request::class); - $this->mixPanel->people->set($user->id, $data, $request->ip()); + $this->mixPanel->people->set($user->getKey(), $data, $request->ip()); $this->mixPanel->track('Session', ['Status' => 'Logged In']); } @@ -81,7 +81,7 @@ public function onUserLogin(Model $user) public function onUserLogout(Model $user = null) { if ($user) { - $this->mixPanel->identify($user->id); + $this->mixPanel->identify($user->getKey()); } $this->mixPanel->track('Session', ['Status' => 'Logged Out']); @@ -94,8 +94,8 @@ public function onViewLoad($route) $request = App::make(Request::class); if (Auth::check()) { - $this->mixPanel->identify(Auth::user()->id); - $this->mixPanel->people->set(Auth::user()->id, [], $request->ip()); + $this->mixPanel->identify(Auth::user()->getKey()); + $this->mixPanel->people->set(Auth::user()->getKey(), [], $request->ip()); } if (is_array($routeAction) && array_key_exists('as', $routeAction)) { @@ -104,6 +104,7 @@ public function onViewLoad($route) $data['Url'] = $request->getUri(); $data['Referrer'] = $request->header('referer'); + array_filter($data); $this->mixPanel->track('Page View', $data); } diff --git a/src/Listeners/LaravelMixpanelUserObserver.php b/src/Listeners/LaravelMixpanelUserObserver.php index 7a02304..ef1a32b 100644 --- a/src/Listeners/LaravelMixpanelUserObserver.php +++ b/src/Listeners/LaravelMixpanelUserObserver.php @@ -33,7 +33,7 @@ public function created(Model $user) $firstName = implode(' ', $nameParts); } - $data[] = [ + $data = [ '$first_name' => $firstName, '$last_name' => $lastName, ]; @@ -45,7 +45,7 @@ public function created(Model $user) array_filter($data); $request = App::make(Request::class); - $this->mixPanel->people->set($user->id, $data, $request->ip()); + $this->mixPanel->people->set($user->getKey(), $data, $request->ip()); $this->mixPanel->track('User', ['Status' => 'Registered']); } @@ -54,8 +54,7 @@ public function created(Model $user) */ public function saving(Model $user) { - $this->mixPanel->identify($user->id); - $data = []; + $this->mixPanel->identify($user->getKey()); $firstName = $user->first_name ?: ''; $lastName = $user->last_name ?: ''; @@ -66,7 +65,7 @@ public function saving(Model $user) $firstName = implode(' ', $nameParts); } - $data[] = [ + $data = [ '$first_name' => $firstName, '$last_name' => $lastName, '$email' => $user->email, @@ -80,7 +79,7 @@ public function saving(Model $user) if (count($data)) { $request = App::make(Request::class); - $this->mixPanel->people->set($user->id, $data, $request->ip()); + $this->mixPanel->people->set($user->getKey(), $data, $request->ip()); } } @@ -89,7 +88,7 @@ public function saving(Model $user) */ public function deleting(Model $user) { - $this->mixPanel->identify($user->id); + $this->mixPanel->identify($user->getKey()); $this->mixPanel->track('User', ['Status' => 'Deactivated']); } @@ -98,7 +97,7 @@ public function deleting(Model $user) */ public function restored(Model $user) { - $this->mixPanel->identify($user->id); + $this->mixPanel->identify($user->getKey()); $this->mixPanel->track('User', ['Status' => 'Reactivated']); } }