How to use the "userdata" object

If you want to to push information about your visitors to the Symplify user object, you can do so by using the sitegainer.userdata API. These key / value pairs will be set to local storage and can be used in both Audience and goals.

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') {
    clearInterval(myInt);
    //set or get userdata
  }
});

 

Example usage in Audience

 

mceclip1.png
Drag a user data statement and enter the key to check for and  how the value should be evaluated.

 

 

Example usage in Goals

mceclip2.png

In Goals you need to use a Custom goal to set this up, Example code below;

//Register goal if user below 20
if(sitegainer.userdata.get('age') < 20) {
	return true;
}

 

 

Was this article helpful?
0 out of 0 found this helpful