Developers

SetUserInfo

Usage

Use this method to set up the user info in the current session:

client.setUserInfo(options:Object);

Note: Remember to set up the session before calling this function.

To start a session see methods generateSession and setSessionToken.

Mandatory parameters

There is not mandatory parameter but the option data is mandatory.

Option

Name Type Default Description
data Object * Mandatory object with data that you want to relate to the user.
logUserAgent boolean 0 Track the user's user agent in user info when set to 1.
logIp boolean 0 Track the user's IP in user info when set to 1.

* Data is mandatory, don't have default value.

Response data format

This method returns a Promise. To log the user information (context) for rating events from non-search sources, the Promise's .then() method must include a call to the corresponding non-search method to ensure the user information has already been sent and stored in the session. If the method fails, use the information provided in the .catch() method to solve the problem.

Example

This is an example in which just after starting the session the user information is set.

var sessionToken = "";
client.generateSession().then(function(response){
    sessionToken = response.data.sessionToken;
    client.setSessionToken(sessionToken);
    client.setUserInfo({
        data:{
            name:"John Doe"
        }
    })
});

This is an example of how to include the user information in ratings from push contents.

sdk.client.generateSession().then(() => {
    sdk.client.setUserInfo({
        data: {
            username: "John Doe",
            company: "Inbenta"
        }
    }).then(() => {
        push = sdk.component('push', '#push', {contents: {showRelated: true}});
    });
});