The SNMobileAnalytics API provides methods that you can call within a WebView using JavaScript. These methods enable you to push custom analytics data (events, pages, and user properties) to the User Experience Analytics for Service Portal dashboard.

To use these methods within your mobile application, you must first call the installJavascriptInterface() method, which exposes these JavaScript methods to the associated WebView.

Refer to NowAnalyticsService - installJavascriptInterface(into webView: WKWebView) for the iOS implementation.

Refer to NowAnalyticsSDK - installJavascriptInterface(webView: WebView) for the Android implementation.

SNMobileAnalytics - addEvent(String eventName, Object properties)

Adds a new web-triggered event with its associated properties to the current mobile session timeline.

Table 1. Parameters
Name Type Description
eventName String Name of the event to add.
properties Object Optional. List of custom property key-value pairs for the event.
Supported value types:
  • Boolean
  • Date
  • Number
  • String
Note: The total size of the eventName, properties key and value should not exceed 300 bytes (per event).
Table 2. Returns
Type Description
None

Example

SNMobileAnalytics.addEvent('MyEvent', JSON.stringify({'Type': 'Show', 'Amount': 16}))

SNMobileAnalytics - addScreenAction(String actionName)

Adds a new screen UI action tag to the current mobile session time line.

Table 3. Parameters
Name Type Description
actionName String Name of the triggered web action.
Table 4. Returns
Type Description
None

Example

SNMobileAnalytics.addScreenAction('Custom UI Action')

SNMobileAnalytics - setUserId(String userId)

Sets the ID of the current active user for the current mobile session.

Table 5. Parameters
Name Type Description
userID String ID to set for the current user.
Table 6. Returns
Type Description
None

Example

SNMobileAnalytics.setUserId('user123') 

SNMobileAnalytics - startScreen(String screenName)

Adds a new web-triggered page to the current mobile session time line.

Table 7. Parameters
Name Type Description
screenName String Name of the screen to log the start time for, such as WelcomeScreen.
Table 8. Returns
Type Description
None

Example

SNMobileAnalytics.startScreen('My Web Page')