PlayerIO

The fastest way to build online games without breaking a sweat.

HTML5 (Javascript) Client Reference

javascript (html5) playerInsight class informationClass playerInsight

Language: Javascript (HTML5)

The PlayerInsight service. This class is used for setting segments for the current user and tracking events in PlayerInsight.

Example

Load PlayerInsight data:

Example

Set segments on the current user:

Example

Track a $1 purchase:

Properties

 
playersOnline :Number

The number of users online in this game. You must call refresh() to initialize this number.

segments :Object

The list of PlayerInsight segments that are set on this user. You must call refresh() to initialize this list.

Methods

 
refresh (successCallback, errorCallback):

Refresh the players online counter and the current segments of the user.

sessionKeepAlive (successCallback, errorCallback):

Keep the PlayerInsight session alive. Call this method if you know the game hasn't made any other API requests in the last 20 minutes, and the player is still playing.

setSegments (segments, successCallback, errorCallback):

Assign custom PlayerInsight segments to the current user

trackEvent (eventType, value, successCallback, errorCallback):

Track the given event for the current user in PlayerInsight

trackExternalPayment (currency, amount, successCallback, errorCallback):

Track a completed payment in PlayerInsight from an external non-PayVault payment method.

trackInvitedBy (invitingUserId, invitationChannel, successCallback, errorCallback):

Tell PlayerInsight who invited the current user in this session. Used for viral analysis.

playerInsight.playersOnline

playersOnline :Number

The number of users online in this game. You must call refresh() to initialize this number.

playerInsight.segments

segments :Object

The list of PlayerInsight segments that are set on this user. You must call refresh() to initialize this list.

playerInsight.refresh

refresh (successCallback, errorCallback):

Refresh the players online counter and the current segments of the user.

Arguments

successCallback:function()
Callback function that will be called when the refresh is complete.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

playerInsight.sessionKeepAlive

sessionKeepAlive (successCallback, errorCallback):

Keep the PlayerInsight session alive. Call this method if you know the game hasn't made any other API requests in the last 20 minutes, and the player is still playing.

Arguments

successCallback:function()
Callback function that will be called when the operation is complete.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

playerInsight.setSegments

setSegments (segments, successCallback, errorCallback):

Assign custom PlayerInsight segments to the current user

Arguments

segments:Object
Custom segments for the user in PlayerInsight
successCallback:function()
Callback function that will be called when the operation is complete.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

playerInsight.trackEvent

trackEvent (eventType, value, successCallback, errorCallback):

Track the given event for the current user in PlayerInsight

Arguments

eventType:string
The name of the event to track.
value:Number
The amount to add to the counter value.
successCallback:function()
Callback function that will be called when the operation is complete.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

playerInsight.trackExternalPayment

trackExternalPayment (currency, amount, successCallback, errorCallback):

Track a completed payment in PlayerInsight from an external non-PayVault payment method.

Arguments

currency:string
The currency the payment was made in.
amount:string
The amount of the payment in the given currency.
successCallback:function()
Callback function that will be called when the operation is complete.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.

playerInsight.trackInvitedBy

trackInvitedBy (invitingUserId, invitationChannel, successCallback, errorCallback):

Tell PlayerInsight who invited the current user in this session. Used for viral analysis.

Arguments

invitingUserId:string
The connectUserId of the user who invited this user.
invitationChannel:string
An identifier for the channel the invitation was received over, like 'email' or 'fb_invite'.
successCallback:function()
Callback function that will be called when the operation is complete.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs.