/** * Alias an existing id with a different unique id. This is helpful when you want to associate a generated id to * a username or e-mail address. * * Because aliasing can be extremely vulnerable to race conditions and ordering issues, we'll make a synchronous * call directly to Mixpanel when this method is called. If it fails we'll throw an Exception as subsequent * events are likely to be incorrectly tracked. * @param string|int $original_id * @param string|int $new_id * @return array $msg * @throws Exception */ public function createAlias($original_id, $new_id) { $msg = array("event" => '$create_alias', "properties" => array("distinct_id" => $original_id, "alias" => $new_id, "token" => $this->_token)); $options = array_merge($this->_options, array("endpoint" => $this->_getEndpoint(), "fork" => false)); $curlConsumer = new ConsumerStrategies_CurlConsumer($options); $success = $curlConsumer->persist(array($msg)); if (!$success) { error_log("Creating Mixpanel Alias (original id: {$original_id}, new id: {$new_id}) failed"); throw new Exception("Tried to create an alias but the call was not successful"); } else { return $msg; } }
protected function _execute_forked($url, $data) { $this->forkedCalls++; return parent::_execute_forked($url, $data); }