mParticle & mParticleInstance Class
All of the following methods can be called on the primary mParticle class. In version 2.10.0, we introduced multiple instances. If you are using multiple instances (self hosted environments only), you should call these methods on each instance.
In current versions of mParticle, if your site has one instance, that instance name is 'default_instance'. Any methods called on mParticle on a site with one instance will be mapped to the default_instance.
This is for simplicity and backwards compatibility. For example, calling mParticle.logPageView() automatically maps to mParticle.getInstance('default_instance').logPageView().
If you have multiple instances, instances must first be initialized and then a method can be called on that instance. For example:
mParticle.init('apiKey', config, 'another_instance');
mParticle.getInstance('another_instance').logPageView();
Item Index
Methods
endSession
()
Ends the current session
getAppName
()
String
Gets the app name
Returns:
App name
getAppVersion
()
String
Gets the app version
Returns:
App version
getEnvironment
()
String
Returns the current mParticle environment setting
Returns:
mParticle environment setting
getVersion
()
String
Returns the mParticle SDK version number
Returns:
mParticle SDK version number
isInitialized
()
Boolean
Returns a boolean for whether or not the SDKhas been fully initialized
Returns:
a boolean for whether or not the SDK has been fully initialized
logError
-
error -
[attrs]
Used to log custom errors
Parameters:
-
errorString or ObjectThe name of the error (string), or an object formed as follows {name: 'exampleName', message: 'exampleMessage', stack: 'exampleStack'}
-
[attrs]Object optionalCustom attrs to be passed along with the error event; values must be string, number, or boolean
logEvent
-
eventName -
[eventType] The eventType as seen [here] -
[eventInfo] -
[customFlags] -
[eventOptions]
Logs an event to mParticle's servers
Parameters:
-
eventNameStringThe name of the event
-
[eventType] The eventType as seen [here]Number optional -
[eventInfo]Object optionalAttributes for the event
-
[customFlags]Object optionalAdditional customFlags
-
[eventOptions]Object optionalFor Event-level Configuration Options
logForm
-
selector -
[eventName] -
[eventType] The eventType as seen [here] -
[eventInfo]
Logs submit events
Parameters:
-
selectorStringThe selector to add the event handler to (ex. #search-event)
-
[eventName]String optionalThe name of the event
-
[eventType] The eventType as seen [here]Number optional -
[eventInfo]Object optionalAttributes for the event
logLink
-
selector -
[eventName] -
[eventType] The eventType as seen [here] -
[eventInfo]
Logs click events
Parameters:
-
selectorStringThe selector to add a 'click' event to (ex. #purchase-event)
-
[eventName]String optionalThe name of the event
-
[eventType] The eventType as seen [here]Number optional -
[eventInfo]Object optionalAttributes for the event
logPageView
-
eventName -
[attrs] -
[customFlags] -
[eventOptions]
Logs a page view
Parameters:
-
eventNameStringThe name of the event. Defaults to 'PageView'.
-
[attrs]Object optionalAttributes for the event
-
[customFlags]Object optionalCustom flags for the event
-
[eventOptions]Object optionalFor Event-level Configuration Options
ready
-
function
A callback method that is invoked after mParticle is initialized.
Parameters:
-
functionFunctionA function to be called after mParticle is initialized
reset
()
Resets the SDK to an uninitialized state and removes cookies/localStorage. You MUST call mParticle.init(apiKey, window.mParticle.config) before any other mParticle methods or the SDK will not function as intended.
setAppName
-
name
Sets the app name
Parameters:
-
nameStringApp Name
setAppVersion
-
version
Sets the app version
Parameters:
-
versionStringversion number
setDeviceId
-
name
Sets the device id
Parameters:
-
nameStringdevice ID (UUIDv4-formatted string)
setLogLevel
-
logLevel
Resets the SDK to an uninitialized state and removes cookies/localStorage. You MUST call mParticle.init(apiKey, window.mParticle.config) before any other mParticle methods or the SDK will not function as intended.
Parameters:
-
logLevelStringverbose, warning, or none. By default,
warningis chosen.
setPosition
-
lattitude -
longitude
Sets the position of the user
Parameters:
-
lattitudeNumberlattitude digit
-
longitudeNumberlongitude digit
startNewSession
()
Starts a new session
startTrackingLocation
-
[callback]
Starts tracking the location of the user
Parameters:
-
[callback]Function optionalA callback function that is called when the location is either allowed or rejected by the user. A position object of schema {coords: {latitude: number, longitude: number}} is passed to the callback
stopTrackingLocation
()
Stops tracking the location of the user
upload
()
Forces an upload of the batch
