How to use the ”userdata” object

If you want to to push information about your visitors to the SiteGainer user object, you can do so by using the sitegainer.userdata api.

To retrieve values in the object, use ”sitegainer.userdata.set”.

sitegainer.userdata.set([key],[value]);
// Examples
sitegainer.userdata.set('age',26);
sitegainer.userdata.set('gender','female');
sitegainer.userdata.set('purchaseAmount',2562);
sitegainer.userdata.set('totalPurchases',3);
sitegainer.userdata.set('timesInCheckout',7);
sitegainer.userdata.set('productPageVisits',7);

To retrieve values from the object, just use ”sitegainer.userdata.get”.

sitegainer.userdata.get([key]);
// Examples
sitegainer.userdata.get('age');
sitegainer.userdata.get('gender');
sitegainer.userdata.get('purchaseAmount');
sitegainer.userdata.get('totalPurchases');
sitegainer.userdata.get('timesInCheckout');
sitegainer.userdata.get('productPageVisits');

Notice: If you are trying to reach the sitegainer api before document ready, make sure you check that it exists. You can do this by using intervals:

var myInt = setInterval(function() {
   if(typeof sitegainer !== 'undefined') {
      console.log(sitegainer);
      clearInterval(myInt); 
   }
});