Skip to content

Commit

Permalink
Merge pull request #43 from utopia-php/update-mixpanel-adapter
Browse files Browse the repository at this point in the history
feat: filter empty values before sending event
  • Loading branch information
christyjacob4 authored Mar 22, 2023
2 parents 70ada5e + ef16953 commit 14c8051
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Analytics/Adapter/Mixpanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ public function send(Event $event): bool
'url' => $event->getUrl(),
];

$properties = array_filter($properties, function ($value) {
if (is_array($value)) {
return ! empty($value);
}

return ! is_null($value) && $value !== '';
});

foreach ($event->getProps() as $key => $value) {
if (! isset($properties[$key])) {
if (! isset($properties[$key]) && ! is_null($value) && $value !== '' && ! empty($value)) {
$properties[$key] = $value;
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Analytics/AnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public function testMixpanel()
'custom_prop1' => 'custom_value1',
'custom_prop2' => 'custom_value2',
'custom_prop3' => 'custom_value3',
'custom_prop4' => '',
'custom_prop5' => null,
'custom_prop6' => [],
]);

$this->assertTrue($this->mp->send($event));
Expand Down

0 comments on commit 14c8051

Please sign in to comment.