API Docs for: 2.11.15
Show:

mParticle & mParticleInstance Class

Defined in: src/mp-instance.js:41

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();

Methods

endSession

()

Ends the current session

getAppName

() String

Gets the app name

Returns:

String:

App name

getAppVersion

() String

Gets the app version

Returns:

String:

App version

getVersion

() String

Returns the mParticle SDK version number

Returns:

String:

mParticle SDK version number

logError

(
  • error
  • [attrs]
)

Used to log custom errors

Parameters:

  • error String or Object

    The name of the error (string), or an object formed as follows {name: 'exampleName', message: 'exampleMessage', stack: 'exampleStack'}

  • [attrs] Object optional

    Custom 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]
)

Logs an event to mParticle's servers

Parameters:

logForm

(
  • selector
  • [eventName]
  • [eventType] The eventType as seen [here]
  • [eventInfo]
)

Logs submit events

Parameters:

logPageView

(
  • eventName
  • [attrs]
  • [customFlags]
)

Logs a page view

Parameters:

  • eventName String

    The name of the event. Defaults to 'PageView'.

  • [attrs] Object optional

    Attributes for the event

  • [customFlags] Object optional

    Custom flags for the event

ready

(
  • function
)

A callback method that is invoked after mParticle is initialized.

Parameters:

  • function Function

    A 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:

  • name String

    App Name

setAppVersion

(
  • version
)

Sets the app version

Parameters:

  • version String

    version number

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:

  • logLevel String

    verbose, warning, or none. By default, warning is chosen.

setPosition

(
  • lattitude
  • longitude
)

Sets the position of the user

Parameters:

  • lattitude Number

    lattitude digit

  • longitude Number

    longitude digit

startNewSession

()

Starts a new session

startTrackingLocation

(
  • [callback]
)

Starts tracking the location of the user

Parameters:

  • [callback] Function optional

    A 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