function testTimestamps() { $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "integer-timestamp", "timestamp" => (int) mktime(0, 0, 0, date('n'), 1, date('Y'))))); $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "string-integer-timestamp", "timestamp" => (string) mktime(0, 0, 0, date('n'), 1, date('Y'))))); $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "iso8630-timestamp", "timestamp" => date(DATE_ATOM, mktime(0, 0, 0, date('n'), 1, date('Y')))))); $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "iso8601-timestamp", "timestamp" => date(DATE_ATOM, mktime(0, 0, 0, date('n'), 1, date('Y')))))); $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "strtotime-timestamp", "timestamp" => strtotime('1 week ago')))); $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "microtime-timestamp", "timestamp" => microtime(true)))); $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "invalid-float-timestamp", "timestamp" => (string) mktime(0, 0, 0, date('n'), 1, date('Y')) . '.'))); }
/** * 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 testEmptyArrayProperties() { $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "empty-properties", "properties" => array()))); $this->assertTrue(Segment::page(array("category" => "empty-properties", "name" => "empty-properties", "userId" => "user-id", "properties" => array()))); }