/** * Alias the user in the analytics system * * @param array $alias The array of data for Segment's \Analytics::alias() * @param bool $js Set this to generate the content as JS once you run render() * @param array $js_options The array of options to set for the JS "options" parameter - "integrations" * options get specified in $alias, but may be overridden here. * @param string $js_callback If you want to use a callback function with "alias," specify it here. * * @return mixed True or false depending on if the PHP version succeeded, or the JS code if we compiled the JS code */ public function alias(array $alias = array(), $js = true, array $js_options = array(), $js_callback = null) { // Set the previousId $alias['previousId'] = empty($alias['previousId']) ? $this->identity['anonymousId'] : $alias['previousId']; // Try to locate the userId. if (empty($alias['userId'])) { $alias['userId'] = $this->identity['userId']; } // Be sure to keep things synchronized. if (!empty($alias['userId'])) { $this->set_user_id($alias['userId']); } if ($js !== true) { return \Analytics::alias($alias); } else { // User ID $js_params[] = "'" . $alias['userId'] . "'"; // Anonymous ID $js_params[] = !empty($alias['previousId']) ? "'" . $alias['previousId'] . "'" : "null"; // JS Options $js_params[] = $this->_set_js_options($js_options, $alias); // JS Callback $js_params[] = !empty($js_callback) ? $js_callback : 'null'; // Add it to the queue. return $this->_js_scripts['alias'] = 'analytics.alias(' . implode(',', $js_params) . ');analytics.flush();'; } }
function testAlias() { $aliased = Analytics::alias("some_user", "new_user"); $this->assertTrue($aliased); }