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

$_super_properties

$_super_properties : array

An array of properties to attach to every tracked event

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 "events" endpoint

Returns

string

track()

track(string  $event, array  $properties = array()) 

Track an event defined by $event associated with metadata defined by $properties

Parameters

string $event
array $properties

register()

register(string  $property, mixed  $value) 

Register a property to be sent with every event. If the property has already been registered, it will be overwritten.

Parameters

string $property
mixed $value

registerAll()

registerAll(array  $props_and_vals = array()) 

Register multiple properties to be sent with every event. If any of the properties have already been registered, they will be overwritten.

Parameters

array $props_and_vals

registerOnce()

registerOnce(  $property,   $value) 

Register a property to be sent with every event. If the property has already been registered, it will NOT be overwritten.

Parameters

$property
$value

registerAllOnce()

registerAllOnce(array  $props_and_vals = array()) 

Register multiple properties to be sent with every event. If any of the properties have already been registered, they will NOT be overwritten.

Parameters

array $props_and_vals

unregister()

unregister(string  $property) 

Un-register an property to be sent with every event.

Parameters

string $property

unregisterAll()

unregisterAll(array  $properties) 

Un-register a list of properties to be sent with every event.

Parameters

array $properties

getProperty()

getProperty(string  $property) : mixed

Get a property that is set to be sent with every event

Parameters

string $property

Returns

mixed

identify()

identify(string|integer  $user_id, [optional] string|integer $anon_id) 

Identify the user you want to associate to tracked events. The $anon_id must be UUID v4 format and not already merged to an $identified_id. All identify calls with a new and valid $anon_id will trigger a track $identify event, and merge to the $identified_id.

Parameters

string|integer $user_id
string|integer $anon_id

createAlias()

createAlias(string|integer  $distinct_id, string|integer  $alias) : array

An alias to be merged with the distinct_id. Each alias can only map to one distinct_id. This is helpful when you want to associate a generated id (such as a session id) to a user id or username.

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.

Parameters

string|integer $distinct_id
string|integer $alias

Throws

\Exception

Returns

array —

$msg

_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