Personalization with the JavaScript SDK

With the JavaScript SDK, you can leverage the personalization features of Sitefinity Insight via the personalizationClient. The following sections explain how to check whether a subject is recognized as a persona or has scored points to a lead scoring type. For a list with Sitefinity Insight terms, see Terminology.

Personalization by persona

You use the isInPersonas function of the personalizationClient to check whether a subject is recognized as a particular persona or to get a list with all personas, to which the subject is associated. You use the following syntax, followed by the parameters' description:

isInPersonas: function(scoringIds, doneCallback, failCallback, subjectKey)

Parameter name Required Data type Description
scoringIds Yes Integer[] An array of persona IDs throughout which you want to check whether the subject belongs to. To get a list of all associated personas, simply pass an empty array.
doneCallback No Function The function that is called with the response of the GET /analytics/v1/scorings/personas/in endpoint upon a successful call.
failCallback No Function The function that is called with the response of the GET /analytics/v1/scorings/personas/in endpoint upon a failed call.
subjectKey No String The subject ID of the subject to be checked for association with any persona. If you do not pass this parameter, the subject ID from the Sitefinity Insight JavaScript SDK cookie is used.

The method returns the response from the GET /analytics/v1/scorings/personas/in endpoint. For more information about endpoints, see Personalization API endpoints.

In the following example, the code checks whether the contact with subject ID “john.smith@test.com” is recognized as the personas with IDs 59 or 60 in Sitefinity Insight:

You can also get a list of all personas, to which the contact is associated by not providing a subject ID and passing an empty array for the personas ID:

decClient.personalizationClient.isInPersonas([], onSuccess, onFailure);

In both examples, you get an array of ScoringResult upon successful call. For more information, see Personalization API endpoints.

Personalization by Lead scoring

You use the isInLeads function to get information about the lead scorings in relation to a subject. You can use this method with both versions of the JavaScript SDK data types. For more information, see Collect data.

Data types v1

You use the isInLeads located in the personalizationClient to check whether subjects have scored toward a particular lead scoring type. You can also get a list all lead scoring types subjects are associated to. In addition, you can check for subjects in different data sources at the same time.

You use the following syntax, followed by the parameters' description:

isInLeads: function(scoringIds, contactsDetails, doneCallback, failCallback)

Parameter name Required Data type Description
scoringIds Yes Integer[] An array of lead scoring types IDs you want to check whether the subject belongs to. To get a list of all associated lead scoring types the contact is associated to, simply pass an empty array.
contactsDetails Yes Stringified object

An object containing information about the subject IDs to check, grouped by data source name, for example:

{

"Data Source 1 Name": [“Subject Id of Client 1”, “Subject Id of Client 2”],

"Data Source 2 Name": [“Subject Id of Client 3”, “Subject Id of Client 4”]

}

NOTE: The object must be strigified to be passed.

doneCallback No Function The function that is called with the response of GET /analytics/v1/scorings/leads/in endpoint upon a successful call.
failCallback No Function The function that is called with the response of the GET /analytics/v1/scorings/leads/in endpoint upon a failed call.

Upon successful call, the method returns an array of LeadScoringResultReport. For more information about endpoints, see Personalization API endpoints.

The example below returns information whether subject 1353 reported from data source Website and subject jane.doe reported from data source Mobile are associated to lead scorings types with IDs 73 and 74 in Sitefinity Insight:

You can modify contact details and the call to the isInLeads function to get all of the lead scorings a particular subject, for example, jane.doe, is associated to:

In both examples, upon successful call to the endpoint, the method returns an object, similar to the one below:

Data types v2

You use the isInLeads located in the v2.personalizationClient to check the status of a single subject in relation to a particular set of lead scoring types or in relation to all lead scoring types in the data center.

You use the following syntax, followed by the parameters' description:

isInLeads: function(scoringIds, doneCallback, failCallback, subjectKey)

Parameter name Required Data type Description
scoringIds Yes Integer[] An array of lead scoring types IDs you want to check whether the subject belongs to. To get a list of all associated lead scoring types the contact is associated to, simply pass an empty array.
doneCallback No Function The function that is called with the response of GET /analytics/v2/scorings/leads/in endpoint upon a successful call.
failCallback No Function The function that is called with the response of the GET /analytics/v2/scorings/leads/in endpoint upon a failed call.
subjectKey No String The subject ID of the contact whose status you want to check. If you do not pass this parameter, the subject ID from the JavaScript SDK cookie is used.

The method returns the response from the GET /analytics/v2/scorings/leads/in endpoint as is. For possible responses and their data types, see Personalization API endpoints.

In the example below, the code returns the status of the subject “john.smith” in relation to lead scoring types 73, 74 and 75:

Upon successful response from the endpoint, the function returns an object similar to the one below. Note that data is returned even for a lead scoring type, in this case 75, the subject is not associated to:

Further resources

You can take a look at the Sitefinity Insight samples:

Was this article helpful?