Properties

$_token

$_token : string

Type

string — a token associated to a Mixpanel project

$_max_queue_size

$_max_queue_size : integer

If the queue reaches this size we'll auto-flush to prevent out of memory errors

Type

integer

$_options

$_options : array

An array of options to be used by the Mixpanel library.

Type

array

$_queue

$_queue : array

Type

array — a queue to hold messages in memory before flushing in batches

$_consumers

$_consumers : array

Type

array — The list of available consumers

$_defaults

$_defaults : array

Default options that can be overridden via the $options constructor arg

Type

array

Methods

__construct()

__construct(array  $options = array()) 

Construct a new MixpanelBase object and merge custom options with defaults

Parameters

array $options

__destruct()

__destruct() 

Flush the queue when we destruct the client with retries

flush()

flush(integer  $desired_batch_size = 50) : boolean

Iterate the queue and write in batches using the instantiated Consumer Strategy

Parameters

integer $desired_batch_size

Returns

boolean —

whether or not the flush was successful

reset()

reset() 

Empties the queue without persisting any of the messages

getQueue()

getQueue() : array

Returns the in-memory queue

Returns

array

getToken()

getToken() : string

Returns the current Mixpanel project token

Returns

string

enqueue()

enqueue(array  $message = array()) 

Add an array representing a message to be sent to Mixpanel to a queue.

Parameters

array $message

enqueueAll()

enqueueAll(array  $messages = array()) 

Add an array representing a list of messages to be sent to Mixpanel to a queue.

Parameters

array $messages

_getEndpoint()

_getEndpoint() : string

Returns the "engage" endpoint

Returns

string

set()

set(string|integer  $distinct_id, array  $props, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Set properties on a user record. If the profile does not exist, it creates it with these properties.

If it does exist, it sets the properties to these values, overwriting existing values.

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

array $props

associative array of properties to set on the profile

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

setOnce()

setOnce(string|integer  $distinct_id, array  $props, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Set properties on a user record. If the profile does not exist, it creates it with these properties.

If it does exist, it sets the properties to these values but WILL NOT overwrite existing values.

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

array $props

associative array of properties to set on the profile

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

remove()

remove(string|integer  $distinct_id, array  $props, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Unset properties on a user record. If the profile does not exist, it creates it with no properties.

If it does exist, it unsets these properties. NOTE: In other libraries we use 'unset' which is a reserved word in PHP.

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

array $props

associative array of properties to unset on the profile

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

increment()

increment(string|integer  $distinct_id,   $prop, integer  $val, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Increments the value of a property on a user record. If the profile does not exist, it creates it and sets the property to the increment value.

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

$prop

string the property to increment

integer $val

the amount to increment the property by

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

append()

append(string|integer  $distinct_id, string  $prop, string|array  $val, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Adds $val to a list located at $prop. If the property does not exist, it will be created. If $val is a string and the list is empty or does not exist, a new list with one value will be created.

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

string $prop

the property that holds the list

string|array $val

items to add to the list

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

trackCharge()

trackCharge(string|integer  $distinct_id, string  $amount, null  $timestamp = null, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Adds a transaction to the user's profile for revenue tracking

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

string $amount

the transaction amount e.g. "20.50"

null $timestamp

the timestamp of when the transaction occurred (default to current timestamp)

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

clearCharges()

clearCharges(string|integer  $distinct_id, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Clear all transactions stored on a user's profile

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

deleteUser()

deleteUser(string|integer  $distinct_id, string|null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) 

Delete this profile from Mixpanel

Parameters

string|integer $distinct_id

the distinct_id or alias of a user

string|null $ip

the ip address of the client (used for geo-location)

boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

_persist()

_persist(  $message) : mixed

Given an array of messages, persist it with the instantiated Persistence Strategy

Parameters

$message

Returns

mixed

_log()

_log(  $msg) 

Log a message to PHP's error log

Parameters

$msg

_debug()

_debug() : boolean

Returns true if in debug mode, false if in production mode

Returns

boolean

_constructPayload()

_constructPayload(  $distinct_id,   $operation,   $value, null  $ip = null, boolean  $ignore_time = false, boolean  $ignore_alias = false) : array

Internal method to prepare a message given the message data

Parameters

$distinct_id
$operation
$value
null $ip
boolean $ignore_time

If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time

boolean $ignore_alias

If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found

Returns

array