Skip to content

Commit

Permalink
Fix incorrect array for mixpanel data, fix reference to user primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Oct 25, 2015
1 parent 5c8eea4 commit b04fba4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions src/Listeners/LaravelMixpanelEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
Expand All @@ -57,7 +57,7 @@ public function onUserLogin(Model $user)
$firstName = implode(' ', $nameParts);
}

$data[] = [
$data = [
'$first_name' => $firstName,
'$last_name' => $lastName,
'$email' => $user->email,
Expand All @@ -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']);
}

Expand All @@ -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']);
Expand All @@ -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)) {
Expand All @@ -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);
}
Expand Down
15 changes: 7 additions & 8 deletions src/Listeners/LaravelMixpanelUserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function created(Model $user)
$firstName = implode(' ', $nameParts);
}

$data[] = [
$data = [
'$first_name' => $firstName,
'$last_name' => $lastName,
];
Expand All @@ -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']);
}

Expand All @@ -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 ?: '';

Expand All @@ -66,7 +65,7 @@ public function saving(Model $user)
$firstName = implode(' ', $nameParts);
}

$data[] = [
$data = [
'$first_name' => $firstName,
'$last_name' => $lastName,
'$email' => $user->email,
Expand All @@ -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());
}
}

Expand All @@ -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']);
}

Expand All @@ -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']);
}
}

0 comments on commit b04fba4

Please sign in to comment.