Skip to main content
Gainsight Inc.

Install Gainsight PX Native-Script

This article explains how developers can use the Gainsight PX NativeScript code in their NativeScript applications.


Gainsight PX can effectively monitor your application, track usage data, provide real-time analytics and display engagement analytics.

You can use the Gainsight PX NativeScript plugin in your mobile application development. This codebase is platform-independent and works with Android and iOS. You can ingest the Gainsight PX code into any mobile application which is developed using the NativeScript application. 

Download and Install NativeScript Plugin

To install the Gainsight PX module:

  1. Download gainsight-px-0.1.6.tgz file from here.

  2. Store the .tgz extension file in the required location.

  3. Add the .tgz file as a dependency in your application `package.json` file;

  • Add the following code to the Dependencies section:

"nativescript-gainsight-px": "file:<path-of-gainsight-px-0.1.6.tgz-file>"

  1. Run,
npm install 

(or equivalent).

Initialize Gainsight PX 

Once you install Gainsight PX, you can use it in your application. 

Note: The code used in this section is platform-independent and can be used in Android or iOS mobile applications.
To track data with Gainsight PX:

  1. Insert the following import code in the header section:
import {Gainsight} from 'nativescript-gainsight-px';
  1. Use the following code to initialize Gainsight PX.
let configurations = new Configurations("<API KEY>")
configurations.enableLogs = true    
    .then(() => {
            console.log("GainsightPX is initialized");
    .catch((error) => {

Note: You must use the initialization code only once in your entire application. (We recommend using this code in the beginning of the app.)


This section explains how to get exceptions if occurred in the SDK. All the Gainsight PX methods return a Promise<GainsightPXCallBack>. The exceptions are passed into catch as errors using GainsightPXCallback interface.

The properties of GainsightPXCallback are as follows:

export interface GainsightPXCallback {
  status: GainsightPXCallbackStatus;
  methodName?: string;
  params?: object;
  exceptionMessage?: string;
export enum GainsightPXCallbackStatus {
  FAILURE = 0,

The properties of GainsightPXCallback are as follows:

  • The status property informs if the created event is success/failure. 
  • The methodName property informs about the invoked function name.
  • The params object gives the event properties that are sent to create an event.
  • The exceptionMessage informs about the exception that occurred.

Screen Events

This section explains how to create events that can track data from your mobile application. Events are actions associated with your app and allow you to track various actions performed by users in your app. Currently, the Gainsight PX SDK supports four types of events.
You can use the Screen event to track each of your screens visited by the user. The syntax to capture screen events is as follows:

GainsightPX.getInstance().screenEvent("<#screen-name#>", "<#screen-class#>");

You can also create a screen event to just capture the name of the screen and exclude all of the other details.

GainsightPX.getInstance().screen("<#screen-name#>", "<#map#>")

Custom Events 

Custom Events are used to track specific actions in your app.

The syntax to track custom events is:

GainsightPX.getInstance().customEventWithProperties(<#custom_event_name#>, <#map#>);

You can also track custom events without any properties.

The syntax for this is:


Identify Events

These events are used to identify a user or an Account uniquely. Gainsight PX provides you with the following syntax:

GainsightPX.getInstance().identify(<#user#>, <#account#>)

The following line of code can be used to track a user: 

var user = new PXUser("<#user_id#>")
user.usem = ""

The list of properties supported for User tracking is given in the table below:

Property Data type
ide String
usem String (Email)
userHash String
gender  String
lastName String
firstName String
signUpDate Date
title String
role String
subscriptionId String
phone String
countryCode String
countryName String
stateCode String
stateName String
city String
street String
continent String
postalCode String
regionName String
timezone String
longitude Double
latitude Double
organization String
organizationEmployees String
organizationRevenue String
organizationIndustry String
organizationSicCode String
organizationDuns Int
accountID String
firstVisitDate Date
score Int
sfdcContactId String
customAttributes Map<String, Any>

The list of Attributes for Account Object are given in the table below:

Property  Data Type
name String
trackedSubscriptionId String
industry String
numberOfEmployees int
sicCode String
website String
naicsCode String
plan String
countryCode String
countryName String
stateCode String
stateName String
city String
street String
continent String
postalCode String
regionName String
timezone String
latitude Double
longitude Double
sfdcId String
customAttributes Map<String, Any>

Set Global Context 

Once you create all the required events, you can set events with a global context. You can set a global context with key-value pairs and send them with the payload. Global context can be set on Date, String, Double, and Boolean data types. Global Context data is stored at the memory level and not disk-level. The key-value pairs are sent with the Payloads. If an application is terminated, all the key-value pairs are erased. 

The following code snippet can be used to set the global context:

GainsightPX.getInstance().setGlobalContext(<#[String: GlobalContextValue]#>);

The following code snippet can be used to check if key is available:

GainsightPX.getInstance().hasGlobalContextKey(<#Name of the key#>)

The following code snippet can be used to remove the key:

GainsightPX.getInstance().removeGlobalContextKeys(<#Array Of Keys#>)

General Methods

This section describes the general methods (functions) of Gainsight PX SDK. There are three general methods:

Method Name Method Description
Flush Gainsight.flush() This method sends all events in the queue to the server, by ignoring the scheduled auto flush. Generally, you need not use this method but there could be situations in which you may need to flush out events.
Enable/Disable Gainsight.enable()

These methods help you to enable or disable event tracking on your app. When you use the disable method, no event is sent to the server. You can use the disable method on data sensitive areas of your app.

Gainsight PX Configurations

This section describes methods, whose configurations can be modified by you during the initialization stage. 

Method Call Default Description Override by Server?
flushQueueSize 20 The number of events that are considered to form a batch to be sent to the server. Once this limit is reached, PX sends the events to the server even if it's still not the time for that (by the timer) Yes
flushInterval 20 sec The time interval during which the client checks if there are any new events to send to the server Yes
collectDeviceId (this method is applicable only to Android application) true Whether or not to collect the device id from the device No
enableLogs False Which log level should be logged to CatLog. By default false is logged No
trackApplicationLifecycleEvents true Should the client auto-track app-related events (APP_OPENED, APP_INSTALLED, and APP_UPDATED) No
(Server can drop the event based on remote configuration
shouldtrackTapEvents false

Should the client auto-track tap events

Note: Enabling this helps you track only the single tap gestures.

  • Was this article helpful?