From 789273cbff88fe4192dd7d79f56ed175ab2d0f64 Mon Sep 17 00:00:00 2001 From: Albert Haff Date: Thu, 11 Jul 2019 21:49:47 +0200 Subject: [PATCH] Support GeoLocation while using queus --- src/LaravelMixpanel.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/LaravelMixpanel.php b/src/LaravelMixpanel.php index eba335d..7e6ae89 100644 --- a/src/LaravelMixpanel.php +++ b/src/LaravelMixpanel.php @@ -27,7 +27,7 @@ public function __construct(Request $request, array $options = []) ); } - public function track($event, $properties = []) + public function getData() { $browserInfo = new Browser(); $osInfo = new Os(); @@ -35,6 +35,7 @@ public function track($event, $properties = []) $browserVersion = trim(str_replace('unknown', '', $browserInfo->getName() . ' ' . $browserInfo->getVersion())); $osVersion = trim(str_replace('unknown', '', $osInfo->getName() . ' ' . $osInfo->getVersion())); $hardwareVersion = trim(str_replace('unknown', '', $deviceInfo->getName())); + $data = [ 'Url' => $this->request->getUri(), 'Operating System' => $osVersion, @@ -46,13 +47,19 @@ public function track($event, $properties = []) : null), 'ip' => $this->request->ip(), ]; - $data = array_filter($data); - $properties = array_filter($properties); if ((! array_key_exists('$browser', $data)) && $browserInfo->isRobot()) { $data['$browser'] = 'Robot'; } - parent::track($event, $data + $properties); + return $data; + } + + public function track($event, $properties = []) + { + $data = array_filter($this->getData()); + $properties = array_filter($properties); + + parent::track($event, $properties + $data); } }