---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# SNMobileAnalytics API

# SNMobileAnalytics API {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

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)](https://servicenow-prod.fluidtopics.net/BbHYbABSv6yhida7B73Hgw#NAnalyServiOS-installJSInterface_O "Enables the calling of the methods in the SNAnalytics() API from within a WebView using JavaScript.") for the iOS implementation.

Refer to [NowAnalyticsSDK - installJavascriptInterface(webView: WebView)](https://servicenow-prod.fluidtopics.net/tcAuGxWxsbkR0Efsuiuyuw#NAnaly-installJSInterface_O "Enables the calling of javaScript.SNMobileAnalytics methods from within a {@link android.webkit.WebView}, using JavaScript.") for the Android implementation.

## SNMobileAnalytics - addEvent(String eventName, Object properties) {#ariaid-title2}

Adds a new
web-triggered
event with its associated properties to the
current
mobile session timeline.
{#MobAn-addEvent_S_O__table_mqk_vgf_mqb__entry__3}

| 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 {#MobAn-addEvent_S_O__ul_g41_kxy_spb} Note: The total size of the eventName, properties key and value should not exceed 300 bytes (per event). |
[Table 1. Parameters]

{#MobAn-addEvent_S_O__table_mqk_vgf_mqb} {#MobAn-addEvent_S_O__table_nqk_vgf_mqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 2. Returns]

{#MobAn-addEvent_S_O__table_nqk_vgf_mqb}  
<br />

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

## SNMobileAnalytics - addScreenAction(String actionName) {#ariaid-title3}

Adds a new
screen
UI action tag to the current mobile session time line.
{#MobAn-addScreenAction_S__table_iyv_ckf_mqb__entry__3}

| Name | Type | Description |
|-|-|-|
| actionName | String | Name of the triggered web action. |
[Table 3. Parameters]

{#MobAn-addScreenAction_S__table_iyv_ckf_mqb} {#MobAn-addScreenAction_S__table_xdr_53f_mqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 4. Returns]

{#MobAn-addScreenAction_S__table_xdr_53f_mqb}  
<br />

    SNMobileAnalytics.addScreenAction('Custom UI Action')

## SNMobileAnalytics - setUserId(String userId) {#ariaid-title4}

Sets the ID of the current active user for the current mobile session.
{#MobAn-setUserId_O__table_hym_ndf_mqb__entry__3}

| Name | Type | Description |
|-|-|-|
| userID | String | ID to set for the current user. |
[Table 5. Parameters]

{#MobAn-setUserId_O__table_hym_ndf_mqb} {#MobAn-setUserId_O__table_iym_ndf_mqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 6. Returns]

{#MobAn-setUserId_O__table_iym_ndf_mqb}  
<br />

    SNMobileAnalytics.setUserId('user123') 

## SNMobileAnalytics - startScreen(String screenName) {#ariaid-title5}

Adds
a new web-triggered page to the current mobile session time line.
{#MobAn-startScreen_S__table_wdr_53f_mqb__entry__3}

| Name | Type | Description |
|-|-|-|
| screenName | String | Name of the screen to log the start time for, such as <kbd class="ph userinput">WelcomeScreen</kbd>. |
[Table 7. Parameters]

{#MobAn-startScreen_S__table_wdr_53f_mqb} {#MobAn-startScreen_S__table_xdr_53f_mqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 8. Returns]

{#MobAn-startScreen_S__table_xdr_53f_mqb}  
<br />

    SNMobileAnalytics.startScreen('My Web Page')


