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.

Overview

Gainsight PX can effectively monitor your application, track usage data, and provide real-time 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. When you ingest Gainsight PX’s NativeScript plugin code in your NativeScript application, Gainsight PX starts tracking all of the data on your application.  

Use Gainsight PX

To use Gainsight PX in your application, you must first download and install NativeScript Plugin. Once completed, After installing Gainsight PX, initialize Gainsight PX and then create events to track data from your application. 

The first step requires developers to download and install the Gainsight PX plugin and other prerequisites on their system.  

Download and Install NativeScript Plugin

To download and install NativeScript Plugin, you must use Gainsight PX’s Tar Archive (.tgz extension) file. This file is a prerequisite to use Gainsight PX.  You can download this file from the Gainsight PX server. Once you download the file, you must add it as a dependency in your JSON file and then install it to your NativeScript application. 

To download the native-script plugin:

  1. Download gainsight-px-0.1.6.tgz.

  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>"

OR

yarn add <path-of-gainsight-px-0.1.6.tgz-file> --save

  1. Save and close your application JSON file.

  2. Launch Terminal.

  3. Install Gainsight PX by running the following code:  
    Note: Press Enter after each line of code.

cd <file path of your application JSON file>
npm install

Alternatively, you can also use the following single line code instead of two lines of code:

npm install <file-path-of-tgz>   

Initialize Gainsight PX 

Once you complete the download and installation of Gainsight PX, you can use it in your application to track data. 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. Gainsight PX recommends using this code in the launch of the application (`onApplication`) as shown so that tracking can be initialized as soon as the application launched.

import {launchEvent, LaunchEventData, on as applicationOn, run as applicationRun } from "tns-core-modules/application";
import { Gainsight, GainsightPXConfiguration } from "nativescript-gainsight-px";

applicationOn(launchEvent, (args: LaunchEventData) => {
        let configs: GainsightPXConfiguration = {
          apiKey: "<API-KEY>"
      };
      Gainsight.initialize(configs);
});

Once initialization is completed, you can use different code snippets to track different kinds of events in your application.

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

  • Screen Events
  • Custom Events
  • Identify Events
  • Set Global Context

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

Gainsight.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.

Gainsight.screen("<#screen-name#>", "<#map#>");

Custom Events 

Custom Events are used to track specific actions in your app. The syntax to track custom events is:

Gainsight.customEventWithProperties(<#custom_event_name#>, <#map#>);

You can also track custom events without any properties. The syntax for this is:

Gainsight.custom(<#custom_event_name#>);

Identify Events

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

Gainsight.identifyUserId(<#user_id#>);
Gainsight.identifyUser(<#GainsightPXUser#>);
Gainsight.identify(<#GainsightPXUser#>, <#GainsightPXAccount#>);

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

let user: GainsightPXUser = {
ide: this.userId,
usem: "david@gmail.com"
};

The above line of code identifies the user since you have added used the usem property to define the user. 

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

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

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

Gainsight.hasGlobalContextKey(<#Name of the key#>)

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

Gainsight.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()

Gainsight.disable()
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


 

  • Was this article helpful?