Skip to content

Commit 8780d28

Browse files
committed
Fix host reference, implemented getAttribute()
1 parent 84c2f2b commit 8780d28

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1212
- Filter any incoming webhook events that are in test mode.
1313

1414
## [0.4.7 - 0.4.8] - 25 Oct 2015
15+
### Changed
16+
- referenced to user model properties to use `getAttribute()` instead of referencing them directly.
17+
1518
### Added
1619
- tracking of `name` in addition to `first name` and `last name`.
1720
- tracking of `referrer` and `referring domain` to help get additional information for Live View (may not yet work

src/Listeners/LaravelMixpanelEventHandler.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public function onUserLoginAttempt(array $event)
4747
*/
4848
public function onUserLogin(Model $user)
4949
{
50-
$firstName = $user->first_name ?: '';
51-
$lastName = $user->last_name ?: '';
50+
$firstName = $user->getAttribute('first_name');
51+
$lastName = $user->getAttribute('last_name');
5252

53-
if ($user->name) {
54-
$nameParts = explode(' ', $user->name);
53+
if ($user->getAttribute('name')) {
54+
$nameParts = explode(' ', $user->getAttribute('name'));
5555
array_filter($nameParts);
5656
$lastName = array_pop($nameParts);
5757
$firstName = implode(' ', $nameParts);
@@ -60,14 +60,13 @@ public function onUserLogin(Model $user)
6060
$data = [
6161
'$first_name' => $firstName,
6262
'$last_name' => $lastName,
63-
'$name' => $user->name,
64-
'$email' => $user->email,
63+
'$name' => $user->getAttribute('name'),
64+
'$email' => $user->getAttribute('email'),
65+
'$created' => ($user->getAttribute('created_at')
66+
? $user->getAttribute('created_at')->format('Y-m-d\Th:i:s')
67+
: null),
6568
];
6669

67-
if ($user->created_at) {
68-
$data['$created'] = $user->created_at->format('Y-m-d\Th:i:s');
69-
}
70-
7170
array_filter($data);
7271

7372
$this->mixPanel->identify($user->getKey());
@@ -106,7 +105,9 @@ public function onViewLoad($route)
106105
$data['Url'] = $request->getUri();
107106
$data['Referrer'] = $request->header('referer');
108107
$data['$initial_referrer'] = $request->header('referer');
109-
$data['$initial_referring_domain'] = parse_url($request->header('referer'))['host'];
108+
$data['$initial_referring_domain'] = ($request->header('referer')
109+
? parse_url($request->header('referer'))['host']
110+
: null);
110111
array_filter($data);
111112
$this->mixPanel->track('Page View', $data);
112113
}

src/Listeners/LaravelMixpanelUserObserver.php

+18-20
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public function __construct(LaravelMixpanel $mixPanel)
2323
*/
2424
public function created(Model $user)
2525
{
26-
$firstName = $user->first_name ?: '';
27-
$lastName = $user->last_name ?: '';
26+
$firstName = $user->getAttribute('first_name');
27+
$lastName = $user->getAttribute('last_name');
2828

29-
if ($user->name) {
30-
$nameParts = explode(' ', $user->name);
29+
if ($user->getAttribute('name')) {
30+
$nameParts = explode(' ', $user->getAttribute('name'));
3131
array_filter($nameParts);
3232
$lastName = array_pop($nameParts);
3333
$firstName = implode(' ', $nameParts);
@@ -36,14 +36,13 @@ public function created(Model $user)
3636
$data = [
3737
'$first_name' => $firstName,
3838
'$last_name' => $lastName,
39-
'$name' => $user->name,
40-
'$email' => $user->email,
39+
'$name' => $user->getAttribute('name'),
40+
'$email' => $user->getAttribute('email'),
41+
'$created' => ($user->getAttribute('created_at')
42+
? $user->getAttribute('created_at')->format('Y-m-d\Th:i:s')
43+
: null),
4144
];
4245

43-
if ($user->created_at) {
44-
$data['$created'] = $user->created_at->format('Y-m-d\Th:i:s');
45-
}
46-
4746
array_filter($data);
4847

4948
$request = App::make(Request::class);
@@ -57,11 +56,11 @@ public function created(Model $user)
5756
public function saving(Model $user)
5857
{
5958
$this->mixPanel->identify($user->getKey());
60-
$firstName = $user->first_name ?: '';
61-
$lastName = $user->last_name ?: '';
59+
$firstName = $user->getAttribute('first_name');
60+
$lastName = $user->getAttribute('last_name');
6261

63-
if ($user->name) {
64-
$nameParts = explode(' ', $user->name);
62+
if ($user->getAttribute('name')) {
63+
$nameParts = explode(' ', $user->getAttribute('name'));
6564
array_filter($nameParts);
6665
$lastName = array_pop($nameParts);
6766
$firstName = implode(' ', $nameParts);
@@ -70,14 +69,13 @@ public function saving(Model $user)
7069
$data = [
7170
'$first_name' => $firstName,
7271
'$last_name' => $lastName,
73-
'$name' => $user->name,
74-
'$email' => $user->email,
72+
'$name' => $user->getAttribute('name'),
73+
'$email' => $user->getAttribute('email'),
74+
'$created' => ($user->getAttribute('created_at')
75+
? $user->getAttribute('created_at')->format('Y-m-d\Th:i:s')
76+
: null),
7577
];
7678

77-
if ($user->created_at) {
78-
$data['$created'] = $user->created_at->format('Y-m-d\Th:i:s');
79-
}
80-
8179
array_filter($data);
8280

8381
if (count($data)) {

0 commit comments

Comments
 (0)