/** * send summary */ public function sendAll() { // send properties of a certain user foreach ($this->properties as $user => $prop) { if (\Segment::identify(array('userId' => $user, 'traits' => $prop, 'context' => array('active' => false, 'ip' => 0)))) { // remove submitted property unset($this->properties[$user]); } } // track events (of a user) foreach ($this->events as $idx => $stat) { // ordinary action if (\Segment::track(array('userId' => $stat['user'], 'event' => $stat['action'], 'properties' => $stat['additional_info'], 'timestamp' => $stat['time']))) { // remove submitted event // oh yeah this works in php with foreach (do not try at home with a real language) unset($this->events[$idx]); } } return count($this->events) + count($this->properties) === 0; }
function testEmptyArrayTraits() { $this->assertTrue(Segment::identify(array("userId" => "empty-traits", "traits" => array()))); $this->assertTrue(Segment::group(array("userId" => "empty-traits", "groupId" => "empty-traits", "traits" => array()))); }