# 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](https://www.progress.com/documentation/sitefinity-cms/insight/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.

<table class="">
<colgroup><col><col><col><col><col></colgroup>
<tbody>
<tr>
<td class="" width="150"><strong>Property name</strong></td>
<td><strong>Required</strong></td>
<td><strong>Data types v2</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td class="" width="150"><code>predicate</code></td>
<td>Yes</td>
<td>String</td>
<td>The predicate of the sentence.</td>
</tr>
<tr>
<td class="" width="150"><code>object</code></td>
<td>No</td>
<td>String</td>
<td>The object of the sentence.</td>
</tr>
<tr>
<td class="" width="150"><code>subjectMetadata</code></td>
<td>No</td>
<td>

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" }`.

> info  **NOTE**: `KeyValuePair[]` is also supported but is automatically converted to the new format.

</td>
<td>The subject metadata to be sent along with the sentence.</td>
</tr>
<tr>
<td class="" width="150"><code>objectMetadata</code></td>
<td>No</td>
<td>

[Sitefinity Insight API data types](https://www.progress.com/documentation/sitefinity-cms/insight/insight-api-data-types) » *InteractionObjectMetadata*

> info  **NOTE**: `KeyValuePair[]` is also supported but is automatically converted to `InteractionObjectMetadata[]`.

</td>
<td>The object metadata to be sent along with the sentence.</td>
</tr>
<tr>
<td class="" width="150"><code>mappedTo</code></td>
<td>No</td>
<td>

[Sitefinity Insight API data types](https://www.progress.com/documentation/sitefinity-cms/insight/insight-api-data-types) » *InteractionMapping\[]*

</td>
<td>The mapping to be sent along with the sentence.</td>
</tr>
</tbody>
</table>

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

```JavaScript
decClient.sentenceClient.writeSentence({
    predicate: 'Downloaded document',
    object: 'www.website.com/docs/gettingStarted.pdf',
    objectMetadata: {
        'title': 'Getting Started with Us'
    },
    subjectMetadata: {
        'Country': 'Germany'
    }
});
```

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

```JavaScript
decClient.subjectMetadataClient.writeSubjectMetadata(
    {
        "Country": "Germany",
        "City": "Berlin",
        "Company": "Sitefinity",
        "Position": "Developer"
    }
);
```

You can also report subject metadata along with a sentence. For more information, see [Data collection API endpoints](https://www.progress.com/documentation/sitefinity-cms/insight/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](https://www.progress.com/documentation/sitefinity-cms/insight/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)`

 <table>
<colgroup><col><col><col><col></colgroup>
<tbody>
<tr>
<td width="150px;"><strong>Property name</strong></td>
<td><strong>Required</strong></td>
<td><strong>Data type</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><code>secondSubject</code></td>
<td>Yes</td>
<td>String</td>
<td>The subject ID of the contact you wish to map to the one tracked by the Sitefinity Insight JavaScript SDK cookie.</td>
</tr>
<tr>
<td><code>secondDataSource</code></td>
<td>Yes</td>
<td>String</td>
<td>The data source, in which the contact you wish to map to the one tracked by the Sitefinity Insight JS SDK cookie is reported.</td>
</tr>
</tbody>
</table>

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](https://www.progress.com/documentation/sitefinity-cms/insight/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`:

```JavaScript
decClient.sentenceClient.writeSentence({
    mappedTo: [
        {
            "S": "john.smith@email.com",
            "DS": "mobile"
        }
    ]
});
```
