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.

Keep in mind that there are two JavaScript SDK versions, which also reflect the Sitefinity CMS you are working with:

  • JavaScript SDK Data types v1 (Data types v1)
    JavaScript SDK 1.0.0.142 and older - track data from Sitefinity CMS 9.2 and older
  • JavaScript SDK Data types v2 (Data types v2)
    JavaScript SDK 1.1.7 and newer - track data from Sitefinity CMS 10.0 and newer

    RECOMMENDATION: We recommend working with the newer version of the JavaScript SDK that uses Data types v2.

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 v1 Data types v2 Description
predicate Yes  String String The predicate of the sentence. 
object No String String The object of the sentence.
subjectMetadata No KeyValuePair[]

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 KeyValuePair[]

InteractionObjectMetadata[]

NOTE: KeyValuePair[] is also supported but is automatically converted to InteractionObjectMetadata[].

The object metadata to be sent along with the sentence.
mappedTo No N/A InteractionMapping[] The mapping to be sent along with the sentence.

NOTE: You can use this property only when working with SDK v2.

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:

Data types v1

Data types v2

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:

Data types v1

Data types v2

You can also report subject metadata along with a sentence. For more information, see Data collection Sitefinity Insight API v1.

Object metadata

The only way to report object metadata is through a sentence. For more information, see Data collection Sitefinity Insight API v1.

Mappings

The JavaScript SDK reports mapping to Sitefinity Insight via the mappingsClient. You use different functions, depending on the SDK version you are working with:

Data types SDK v1

You use the newMappingWithCurrent function. This function expects the following syntax, followed by the parameters' description:

newMappingWithCurrent (secondSubject, secondDataSource, doneCallback, failCallback)

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 JavaScript SDK cookie is reported.
doneCallback No Function The function that is called with the response of the data collection endpoint upon a successful mapping call.
failCallback No Function The function that is called with the response of the data collection endpoint upon a failed mapping call.

The method calls the POST /collect/v1/mappings endpoint. For more information about the endpoints, see Data collection Sitefinity Insight API v1.

After initializing the SDK into the decClient variable, mapping will looking similar to the following:

Data types v2

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 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:

Was this article helpful?