Skip to main content
Gainsight Inc.

Use Global Context API

This article explains setting up a create Global Context in Gainsight PX via API.

Overview

Gainsight PX Web SDK supports the ability to set a "Global Context" (AKA super properties) for all user interactions captured by the Gainsight PX tracking tag.  Setting the context automatically attaches/assigns those properties/values to all auto-tracked events. 

This functionality helps your organization to :

  • Track different runtime elements like feature-flag, UI version, framework, release version
  • Establish a sustainable instrumentation strategy 
  • Gain greater visibility 
  • Add context to the auto-tracked events that are specific to your organization

Global Context

 The global context can be defined as a list of property/value pairs with the following types supported:

  • string
  • number
  • boolean
  • datetime (ISO 8601 UTC date and time)

Here is an example call:

// Setting Global Context
// Track UI version and runtime

aptrinsic('set', 'globalContext', {"version":12345, "name":"Salesforce", "type":"IFrane"});
aptrinsic('set', 'globalContext', {"version":555, "name":"NXT"});

//Track an object:
aptrinsic('set', 'globalContext', {"projectId":12345,"Project Type" :"Work Order", "Project Date":"2018-03-08T18:11:00Z" });

//

After this call all future events will be populated with global context: projectId=12345, Project Type = "Work Order" etc.

To update an existing value just call set again with the new value and all future events will now use the new value:

// Setting Global Context (Update a property)

aptrinsic('set', 'globalContext', {"projectId":67890});
//

In the above example, the global context value for key "projectId" will now be 67890 for all future events.

But in the case we want to override only if not set before, you can call like this:

aptrinsic('set', 'globalContext', {"projectId" : 67890});
aptrinsic('setOnce', 'globalContext', {"projectId" : 45673})
//
In the above calls, the global context for key "projectId" stays at 67890 and is not overridden by the second call

Remove

Removes a list of global context. This will remove the global context from being populated in future  events but does not effect past events

aptrinsic('remove', 'globalContext', ["projectId"])
//

The above call will no longer include the "projectId" property on future events. 

And finally, one more example:

aptrinsic('set', 'globalContext', {"projectId" : 67890});
//call custom event
aptrinsic('track', 'purchased', {"amount" : 1});
aptrinsic('remove', 'globalContext', ["projectId"]);
//call the same custom event again with different value
aptrinsic('track', 'purchased', {"amount" : 2});
//

In the above example, the first call will assign "projectId=67890" to the "purchased" custom event , but it will not be included as part of the second call. 

  • Was this article helpful?