Collect data
With the JavaScript SDK you can report data to Sitefinity Insight in an easy and straightforward way. The following article describes how to report sentences, metadata and mappings. For a list of Sitefinity Insight terms and description, see Developer terminology.
Sentences
The JavaScript SDK reports sentences via the sentenceClient
, which is automatically initialized as part of the SDK client. You need to use the writeSentence
function, which expects the following object passed to it.
Property name |
Required |
Data types v2 |
Description |
predicate |
Yes |
String |
The predicate of the sentence. |
object |
No |
String |
The object of the sentence. |
subjectMetadata |
No |
A JavaScript object with properties containing the names of the metadata keys and with values - the metadata values. Note that the property values can be only of type string.
For example, { "Email", "user@example.com" }.
NOTE: KeyValuePair[] is also supported but is automatically converted to the new format.
|
The subject metadata to be sent along with the sentence. |
objectMetadata |
No |
InteractionObjectMetadata
NOTE: KeyValuePair[] is also supported but is automatically converted to InteractionObjectMetadata[] .
|
The object metadata to be sent along with the sentence. |
mappedTo |
No |
InteractionMapping[] |
The mapping to be sent along with the sentence. |
NOTE: KeyValuePair
is a JavaScript object containing only two properties, 'K'
, which contains the metadata name, and 'V'
, which contains the metadata value. For example, { 'K': 'Email', 'V': 'user@example.com' }
.
For example, you want to report the following information – a PDF document with location www.website.com/docs/Getting Started.pdf (object) and title “Getting Started with Us” (object metadata) is downloaded (predicate) by a customer from Germany (subject metadata). If you report data via the sentenceClient
and you initialized the SDK into the decClient
variable, data will look similar to this:
Subject metadata
The JavaScript SDK reports data to Sitefinity Insight via the subjectMetadataClient
, which is automatically initialized as part of the SDK client. You need to use the writeSubjectMetadata
function, which expects either KeyValurPair[]
or an object with properties equivalent to the metadata keys and the key values (only strings are supported) - to the metadata value.
For example, you want to report that the current subject is from Germany, lives in Berlin, and is a developer at Sitefinity CMS. To do this, you initialize the SDK into the variable decClient
and use the JavaScript SDK:
You can also report subject metadata along with a sentence. For more information, see Data collection API endpoints.
Object metadata
The only way to report object metadata is through a sentence. For more information, see Data collection API endpoints.
Mappings
The JavaScript SDK reports mapping to Sitefinity Insight via the mappingsClient
.
You use the addMapping
function of the mappingsClient
. This function expects the following syntax, followed by the parameters' description:
addMapping(secondSubject, secondDataSource)
Property name |
Required |
Data type |
Description |
secondSubject |
Yes |
String |
The subject ID of the contact you wish to map to the one tracked by the Sitefinity Insight JavaScript SDK cookie. |
secondDataSource |
Yes |
String |
The data source, in which the contact you wish to map to the one tracked by the Sitefinity Insight JS SDK cookie is reported. |
The method calls the POST /collect/v2/data-centers/{data-source-name}/datasources/{data-source-name}/interactions
endpoint. For more information about the endpoints, see Data collection API endpoints.
After initializing the SDK into the decClient
variable, mapping will looking similar to the following:
decClient.mappingsClient.addMapping("john.smith@email.com", "mobile");
You can also report mappings using the sentenceClient
by providing a mappedTo
property of the object, passed to the writeSentence
function. As with the other example, the following example assumes you have initialized the SDK into the variable decClient
: