Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-smush.../vendor/mixpanel/mixpanel.../lib/Producer...
File: MixpanelEvents.php
<?php
[0] Fix | Delete
require_once(dirname(__FILE__) . "/MixpanelBaseProducer.php");
[1] Fix | Delete
require_once(dirname(__FILE__) . "/MixpanelPeople.php");
[2] Fix | Delete
require_once(dirname(__FILE__) . "/../ConsumerStrategies/CurlConsumer.php");
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* Provides an API to track events on Mixpanel
[6] Fix | Delete
*/
[7] Fix | Delete
class Producers_MixpanelEvents extends Producers_MixpanelBaseProducer {
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* An array of properties to attach to every tracked event
[11] Fix | Delete
* @var array
[12] Fix | Delete
*/
[13] Fix | Delete
private $_super_properties = array("mp_lib" => "php");
[14] Fix | Delete
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Track an event defined by $event associated with metadata defined by $properties
[18] Fix | Delete
* @param string $event
[19] Fix | Delete
* @param array $properties
[20] Fix | Delete
*/
[21] Fix | Delete
public function track($event, $properties = array()) {
[22] Fix | Delete
[23] Fix | Delete
// if no token is passed in, use current token
[24] Fix | Delete
if (!isset($properties["token"])) $properties['token'] = $this->_token;
[25] Fix | Delete
[26] Fix | Delete
// if no time is passed in, use the current time
[27] Fix | Delete
if (!isset($properties["time"])) $properties['time'] = microtime(true);
[28] Fix | Delete
[29] Fix | Delete
$params['event'] = $event;
[30] Fix | Delete
$params['properties'] = array_merge($this->_super_properties, $properties);
[31] Fix | Delete
[32] Fix | Delete
$this->enqueue($params);
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Register a property to be sent with every event. If the property has already been registered, it will be
[38] Fix | Delete
* overwritten.
[39] Fix | Delete
* @param string $property
[40] Fix | Delete
* @param mixed $value
[41] Fix | Delete
*/
[42] Fix | Delete
public function register($property, $value) {
[43] Fix | Delete
$this->_super_properties[$property] = $value;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Register multiple properties to be sent with every event. If any of the properties have already been registered,
[49] Fix | Delete
* they will be overwritten.
[50] Fix | Delete
* @param array $props_and_vals
[51] Fix | Delete
*/
[52] Fix | Delete
public function registerAll($props_and_vals = array()) {
[53] Fix | Delete
foreach($props_and_vals as $property => $value) {
[54] Fix | Delete
$this->register($property, $value);
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Register a property to be sent with every event. If the property has already been registered, it will NOT be
[61] Fix | Delete
* overwritten.
[62] Fix | Delete
* @param $property
[63] Fix | Delete
* @param $value
[64] Fix | Delete
*/
[65] Fix | Delete
public function registerOnce($property, $value) {
[66] Fix | Delete
if (!isset($this->_super_properties[$property])) {
[67] Fix | Delete
$this->register($property, $value);
[68] Fix | Delete
}
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* Register multiple properties to be sent with every event. If any of the properties have already been registered,
[74] Fix | Delete
* they will NOT be overwritten.
[75] Fix | Delete
* @param array $props_and_vals
[76] Fix | Delete
*/
[77] Fix | Delete
public function registerAllOnce($props_and_vals = array()) {
[78] Fix | Delete
foreach($props_and_vals as $property => $value) {
[79] Fix | Delete
if (!isset($this->_super_properties[$property])) {
[80] Fix | Delete
$this->register($property, $value);
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Un-register an property to be sent with every event.
[88] Fix | Delete
* @param string $property
[89] Fix | Delete
*/
[90] Fix | Delete
public function unregister($property) {
[91] Fix | Delete
unset($this->_super_properties[$property]);
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Un-register a list of properties to be sent with every event.
[97] Fix | Delete
* @param array $properties
[98] Fix | Delete
*/
[99] Fix | Delete
public function unregisterAll($properties) {
[100] Fix | Delete
foreach($properties as $property) {
[101] Fix | Delete
$this->unregister($property);
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Get a property that is set to be sent with every event
[108] Fix | Delete
* @param string $property
[109] Fix | Delete
* @return mixed
[110] Fix | Delete
*/
[111] Fix | Delete
public function getProperty($property) {
[112] Fix | Delete
return $this->_super_properties[$property];
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Identify the user you want to associate to tracked events. The $anon_id must be UUID v4 format (optionally with the
[118] Fix | Delete
* prefix '$device:') and not already merged to an $identified_id. All identify calls with a new and valid $anon_id will
[119] Fix | Delete
* trigger a track $identify event, and merge to the $identified_id.
[120] Fix | Delete
* @param string|int $user_id
[121] Fix | Delete
* @param string|int $anon_id [optional]
[122] Fix | Delete
*/
[123] Fix | Delete
public function identify($user_id, $anon_id = null) {
[124] Fix | Delete
$this->register("distinct_id", $user_id);
[125] Fix | Delete
[126] Fix | Delete
$UUIDv4 = '/^(\$device:)?[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*$/i';
[127] Fix | Delete
if (!empty($anon_id)) {
[128] Fix | Delete
if (preg_match($UUIDv4, $anon_id) !== 1) {
[129] Fix | Delete
/* not a valid uuid */
[130] Fix | Delete
error_log("Running Identify method (identified_id: $user_id, anon_id: $anon_id) failed, anon_id not in UUID v4 format");
[131] Fix | Delete
} else {
[132] Fix | Delete
$this->track('$identify', array(
[133] Fix | Delete
'$identified_id' => $user_id,
[134] Fix | Delete
'$anon_id' => $anon_id
[135] Fix | Delete
));
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* An alias to be merged with the distinct_id. Each alias can only map to one distinct_id.
[143] Fix | Delete
* This is helpful when you want to associate a generated id (such as a session id) to a user id or username.
[144] Fix | Delete
*
[145] Fix | Delete
* Because aliasing can be extremely vulnerable to race conditions and ordering issues, we'll make a synchronous
[146] Fix | Delete
* call directly to Mixpanel when this method is called. If it fails we'll throw an Exception as subsequent
[147] Fix | Delete
* events are likely to be incorrectly tracked.
[148] Fix | Delete
* @param string|int $distinct_id
[149] Fix | Delete
* @param string|int $alias
[150] Fix | Delete
* @return array $msg
[151] Fix | Delete
* @throws Exception
[152] Fix | Delete
*/
[153] Fix | Delete
public function createAlias($distinct_id, $alias) {
[154] Fix | Delete
$msg = array(
[155] Fix | Delete
"event" => '$create_alias',
[156] Fix | Delete
"properties" => array("distinct_id" => $distinct_id, "alias" => $alias, "token" => $this->_token)
[157] Fix | Delete
);
[158] Fix | Delete
[159] Fix | Delete
// Save the current fork/async options
[160] Fix | Delete
$old_fork = isset($this->_options['fork']) ? $this->_options['fork'] : false;
[161] Fix | Delete
$old_async = isset($this->_options['async']) ? $this->_options['async'] : false;
[162] Fix | Delete
[163] Fix | Delete
// Override fork/async to make the new consumer synchronous
[164] Fix | Delete
$this->_options['fork'] = false;
[165] Fix | Delete
$this->_options['async'] = false;
[166] Fix | Delete
[167] Fix | Delete
// The name is ambiguous, but this creates a new consumer with current $this->_options
[168] Fix | Delete
$consumer = $this->_getConsumer();
[169] Fix | Delete
$success = $consumer->persist(array($msg));
[170] Fix | Delete
[171] Fix | Delete
// Restore the original fork/async settings
[172] Fix | Delete
$this->_options['fork'] = $old_fork;
[173] Fix | Delete
$this->_options['async'] = $old_async;
[174] Fix | Delete
[175] Fix | Delete
if (!$success) {
[176] Fix | Delete
error_log("Creating Mixpanel Alias (distinct id: $distinct_id, alias: $alias) failed");
[177] Fix | Delete
throw new Exception("Tried to create an alias but the call was not successful");
[178] Fix | Delete
} else {
[179] Fix | Delete
return $msg;
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Returns the "events" endpoint
[186] Fix | Delete
* @return string
[187] Fix | Delete
*/
[188] Fix | Delete
function _getEndpoint() {
[189] Fix | Delete
return $this->_options['events_endpoint'];
[190] Fix | Delete
}
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function