Skip to main content
Gainsight Inc.

How to sample users for tracking using API

This article explains how to use the Gainsight PX tag to sample users.

Sampling User Traffic

Sampling is useful when there are certain types of users you don't wish to track and you would like to reduce tracking volumes while leveraging sampling strategy to gain behavioral insights.

 

If you wish to track 100% of the traffic and wish to sample engagements please use the scheduling and scoping step in Gainsight PX engagement editor.

Sampling can be done by wrapping Gainsight PX tag and using a sampling utility function. You must set the right Product key before using the below code. 

<script type="text/javascript">
src="https://storage.googleapis.com/gainsight-px-cloud-public-assets/sdk/js/gpx-util.js">
</script>   
<script type="text/javascript">
     
    function initializeGainsightPX()
    {       
        // Check to see if user id exists in sample population loading Gainsight PX
        var userID = "abc";  // Set the user's ID
        var visitorType = "guest";  // Set to the user's type
        var samplePercentage = 10;
        if (visitorType !== "guest" ||  __IdSampler.isIdInSamplePopulation(userID,samplePercentage))
        {         
       
        // Load Gainsight Script
          (function (n, t, a, e) {  
              let i = "aptrinsic"; n[i] = n[i] || function () {
                  (n[i].q = n[i].q || []).push(arguments)
              },
              n[i].p = e;             
              let r = t.createElement("script");
              r.async = !0;
              r.src = a + "?a=" + e;                     
              let c = t.getElementsByTagName("script")[0];
              c.parentNode.insertBefore(r, c);
          })
         
          (window, document, "https://web-sdk.aptrinsic.com/api/aptrinsic.js", "AP-XXXXXXXXXXXX-2");
          // End Gainsight PX Tag            }
      }
        
</script>
  • Was this article helpful?