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.
This article describes types and functions available starting with the Sitefinity Insight JavaScript SDK version 1.1.7, which is used to track data starting with Sitefinity CMS 10.0.
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.
NOTE: Keep in mind there are differences in reporting data when working with the two JavaScript versions.
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 |
An object with properties that are equivalent to the metadata keys and whose values - to the metadata value. Note that the property values can be only string.
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. |
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 » Data collection with Sitefinity Insight API v2.
Object metadata
The only way to report object metadata is through a sentence. For more information, see Data collection API endpoints » Data collection with Sitefinity Insight API v2.
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 » Data collection with Sitefinity Insight API v2.
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
: