Skip to content

Commit f2786f8

Browse files
committed
Fixed #47
1 parent 1d8a89b commit f2786f8

File tree

7 files changed

+28
-33
lines changed

7 files changed

+28
-33
lines changed

src/Events/MixpanelEvent.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace GeneaLabs\LaravelMixpanel\Events;
22

33
use Illuminate\Queue\SerializesModels;
4+
use Illuminate\Support\Collection;
45

56
class MixpanelEvent
67
{
@@ -19,14 +20,9 @@ public function __construct($user, array $trackingData, int $charge = 0, array $
1920
$this->user = $user;
2021
}
2122

22-
public function name() : string
23+
public function names() : Collection
2324
{
24-
$name = array_keys($this->trackingData)[0];
25-
26-
if ($name === 0) {
27-
$name = $this->trackingData[0];
28-
}
29-
30-
return $name;
25+
return collect($this->trackingData)
26+
->keys();
3127
}
3228
}

src/Http/Requests/RecordStripeEvent.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ private function recordCharge(array $transaction, $user)
6868
}
6969

7070
$trackingData = [
71-
'Payment',
72-
[
71+
'Payment' => [
7372
'Status' => $status,
7473
'Amount' => $amount,
7574
],
@@ -97,8 +96,8 @@ private function recordSubscription(array $transaction, $user, array $originalVa
9796
->timezone('UTC')) . ' days'
9897
];
9998
$trackingData = [
100-
['Subscription', ['Status' => 'Canceled', 'Upgraded' => false]],
101-
['Churn! :-('],
99+
'Subscription' => ['Status' => 'Canceled', 'Upgraded' => false],
100+
'Churn! :-(' => [],
102101
];
103102
}
104103

@@ -113,12 +112,12 @@ private function recordSubscription(array $transaction, $user, array $originalVa
113112
'Plan When Churned' => $oldPlanName,
114113
];
115114
$trackingData = [
116-
['Subscription', [
115+
'Subscription' => [
117116
'Upgraded' => false,
118117
'FromPlan' => $oldPlanName,
119118
'ToPlan' => $planName,
120-
]],
121-
['Churn! :-('],
119+
],
120+
'Churn! :-(' => [],
122121
];
123122
}
124123

@@ -127,12 +126,12 @@ private function recordSubscription(array $transaction, $user, array $originalVa
127126
'Subscription' => $planName,
128127
];
129128
$trackingData = [
130-
['Subscription', [
129+
'Subscription' => [
131130
'Upgraded' => true,
132131
'FromPlan' => $oldPlanName,
133132
'ToPlan' => $planName,
134-
]],
135-
['Unchurn! :-)'],
133+
],
134+
'Unchurn! :-)' => [],
136135
];
137136
}
138137
} else {
@@ -141,12 +140,12 @@ private function recordSubscription(array $transaction, $user, array $originalVa
141140
'Subscription' => $planName,
142141
];
143142
$trackingData = [
144-
['Subscription', [
143+
'Subscription' => [
145144
'Upgraded' => true,
146145
'FromPlan' => 'Trial',
147146
'ToPlan' => $planName,
148-
]],
149-
['Unchurn! :-)'],
147+
],
148+
'Unchurn! :-)' => [],
150149
];
151150
}
152151
}
@@ -156,7 +155,7 @@ private function recordSubscription(array $transaction, $user, array $originalVa
156155
'Subscription' => $planName,
157156
];
158157
$trackingData = [
159-
['Subscription', ['Status' => 'Created']],
158+
'Subscription' => ['Status' => 'Created'],
160159
];
161160
}
162161

@@ -165,7 +164,7 @@ private function recordSubscription(array $transaction, $user, array $originalVa
165164
'Subscription' => 'Trial',
166165
];
167166
$trackingData = [
168-
['Subscription', ['Status' => 'Trial']],
167+
'Subscription' => ['Status' => 'Trial'],
169168
];
170169
}
171170
}

src/Listeners/LaravelMixpanelUserObserver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ class LaravelMixpanelUserObserver
66
{
77
public function created($user)
88
{
9-
event(new Mixpanel($user, ['User: Registered']));
9+
event(new Mixpanel($user, ['User: Registered' => []]));
1010
}
1111

1212
public function saving($user)
1313
{
14-
event(new Mixpanel($user, ['User: Updated']));
14+
event(new Mixpanel($user, ['User: Updated' => []]));
1515
}
1616

1717
public function deleting($user)
1818
{
19-
event(new Mixpanel($user, ['User: Deactivated']));
19+
event(new Mixpanel($user, ['User: Deactivated' => []]));
2020
}
2121

2222
public function restored($user)
2323
{
24-
event(new Mixpanel($user, ['User: Reactivated']));
24+
event(new Mixpanel($user, ['User: Reactivated' => []]));
2525
}
2626
}

src/Listeners/Login.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class Login
77
{
88
public function handle(LoginEvent $login)
99
{
10-
event(new Mixpanel($login->user, ['User Logged In']));
10+
event(new Mixpanel($login->user, ['User Logged In' => []]));
1111
}
1212
}

src/Listeners/LoginAttempt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public function handle(Attempting $event)
1414
->where('email', $email)
1515
->first();
1616

17-
event(new Mixpanel($user, ['Login Attempted']));
17+
event(new Mixpanel($user, ['Login Attempted' => []]));
1818
}
1919
}

src/Listeners/Logout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class Logout
77
{
88
public function handle(LogoutEvent $logout)
99
{
10-
event(new Mixpanel($logout->user, ['User Logged Out']));
10+
event(new Mixpanel($logout->user, ['User Logged Out' => []]));
1111
}
1212
}

tests/Feature/AuthenticationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testLoginAttempt()
2929
$this->assertResponseStatus(200);
3030
$result->seePageIs('/login');
3131
Event::assertDispatched(MixpanelEvent::class, function ($event) use ($user) {
32-
return ($event->user->email === $user->email && $event->name() === 'Login Attempted');
32+
return ($event->user->email === $user->email && $event->names()->contains('Login Attempted'));
3333
});
3434
}
3535

@@ -49,7 +49,7 @@ public function testLoginSuccess()
4949
$this->assertResponseStatus(200);
5050
$result->seePageIs('/home');
5151
Event::assertDispatched(MixpanelEvent::class, function ($event) use ($user) {
52-
return ($event->user->email === $user->email && $event->name() === 'User Logged In');
52+
return ($event->user->email === $user->email && $event->names()->contains('User Logged In'));
5353
});
5454
}
5555

@@ -63,7 +63,7 @@ public function testLogoutSuccess()
6363

6464
$this->assertRedirectedTo('/');
6565
Event::assertDispatched(MixpanelEvent::class, function ($event) use ($user) {
66-
return ($event->user->email === $user->email && $event->name() === 'User Logged Out');
66+
return ($event->user->email === $user->email && $event->names()->contains('User Logged Out'));
6767
});
6868
}
6969
}

0 commit comments

Comments
 (0)