# Capture client-side behavior with JavaScript SDK

## Overview

With the Sitefinity Insight JavaScript SDK, you can easily track client-side interactions of your website visitors. You can also use the SDK to:

* Personalize the experience of visitors
* Check whether visitors are associated with a certain persona
* Check whether visitors scored points as leads

To create and initialize a new instance of Sitefinity Insight SDK client, in the HTML of your page perform the following:

## Register an initialization callback

In the `<head>` tag of your page, add a `<script>` tag containing the code to create an instance of the Insight SDK client using the following sample:

```JavaScript
function initInsight() {
    var insightClient = new sfDataIntell.Client({
        apiKey: '12345678-1234-1234-1234-1234567890ab', // replace with your Insight data center API key
        apiServerUrl: 'https://api.insight.sitefinity.com', // change this to the API server URL where your Insight account is hosted
        source: 'Website',
        trackPageVisits: true,
        trackBrowserInformation: true,
        trackUtmParameters: true,
        crossDomainTrackingEntries: ["example.org", "example.com"],
        sessionLengthInMinutes: 30,
        trackYouTubeVideos: true,
        trackVimeoVideos: true
    });
}

document.addEventListener('insight-sdk-ready', initInsight);
```

Optionally, you can provide a `settings` object that can contain the following properties:

<table>
<colgroup><col><col><col><col></colgroup>
<tbody>
<tr>
<td width="180"><strong>Name</strong></td>
<td><strong>Required</strong></td>
<td><strong>Data type</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><code>apiKey</code></td>
<td>Yes</td>
<td>GUID</td>
<td>The API key of the data center you want to report data to.</td>
</tr>
<tr>
<td><code>source</code></td>
<td>Yes</td>
<td>String</td>
<td>The name of the data source to which to report data.

> info **RECOMMENDATION**: We recommend using a single data source for all data within a data center in most cases.

For more information, see [Data sources](https://www.progress.com/documentation/sitefinity-cms/insight/data-sources).

</td>
</tr>
<tr>
<td><code>apiServerUrl</code></td>
<td>No</td>
<td>String</td>
<td>

The URL of Sitefinity Insight API server, to which data is reported. The default is the US API server. To learn all available deployment options, see [Sitefinity Insight deployment options](https://www.progress.com/documentation/sitefinity-cms/insight/insight-deployment-options#sitefinity-cms-and-sitefinity-insight-deployments) » *Sitefinity CMS and Sitefinity Insight deployments*.

</td>
</tr>
<tr>
<td><code>trackingCookieDomain</code></td>
<td>No</td>
<td>String</td>
<td>

The cookie domain. For more information, see [Manage cookies](https://www.progress.com/documentation/sitefinity-cms/insight/manage-cookies).

</td>
</tr>
<tr>
<td><code>instrument</code></td>
<td>No</td>
<td>Boolean</td>
<td>

Used for enabling the HTML5 instrumentation tracking. For more information, see [Track visitor activities using HTML attribute instrumentation](https://www.progress.com/documentation/sitefinity-cms/insight/enable-html5-attribute-instrumentation).

</td>
</tr>
<tr>
<td><code>trackPageVisits</code></td>
<td>No</td>
<td>Object</td>
<td>

Used for providing custom attributes to the default page tracker. For more information, see [Track pages](https://www.progress.com/documentation/sitefinity-cms/insight/track-pages).

</td>
</tr>
<tr>
<td><code>trackBrowserInformation</code></td>
<td>No</td>
<td>Boolean</td>
<td>When you set this property to <code>true</code>, Sitefinity Insight adds the following information to the metadata of the visitor&rsquo;s interaction (the <code>subject</code>):<ul>
<li>Information about the current user agent<br>
This is the browser identifier</li>
<li>The browser-supported browser languages</li>
</ul>
</td>
</tr>
<tr>
<td><code>enableTracking</code></td>
<td>No</td>
<td>Boolean</td>
<td>

By default, the value of the property is set to`true`. If you disable this property, no requests are made to the Sitefinity Insight API and no tracking and personalization are executed by the SDK. In accordance with GDPR, the visitor provides consent to be tracked or rejects to be tracked. You set the property value to `true` or `false`, accordingly.

For more information, see [Manage cookies](https://www.progress.com/documentation/sitefinity-cms/insight/manage-cookies).

> info **NOTE**: You can use this parameter only if you are working with JavaScript SDK version 3.0 and newer.

</td>
</tr>
<tr>
<td><code>cookieMaxAgeInDays</code></td>
<td>No</td>
<td>Number</td>
<td>

Default value: `365` (one year). This property specifies the number of days until the tracking cookie expires.

> info **NOTE**: You can use this parameter only if you are working with JavaScript SDK version 3.1.2 and newer.

</td>
</tr>
<tr>
<td><code>cookieSlidingExpiration</code>
</td>
<td>No</td>
<td>Boolean</td>
<td>

Default value: `false`. If enabled, cookie expiration resets every time a front-end page is visited. Unless you set the cookie expiration in the `maxAgeForTrackingCookieInDays` property, the default value of 365 is used.

> info **NOTE**: You can use this parameter only if you are working with JavaScript SDK version 3.1.2 and newer.

</td>
</tr>
<tr>
<td><code>crossDomainTrackingEntries</code></td>
<td>No</td>
<td>Array of strings</td>
<td>

List of domain names of sites for which cross-domain tracking of visitors is performed.

That is, a single physical user is tracked across all these domains and their visitor journeys are merged into one.\
For more information, see [Track interactions across multiple domains](https://www.progress.com/documentation/sitefinity-cms/insight/track-interactions-across-multiple-domains).

> info  **NOTE**: You can use this parameter only if you are working with JavaScript SDK version 3.1.2 and newer.

</td>
</tr>
<tr>
<td><code>sessionLengthInMinutes</code></td>
<td>No</td>
<td>Number</td>
<td>The amount of time in minutes which defines a session - group of interactions that take place within a given time frame.<br>
If the user is inactive for more than the specified number of minutes, next interactions become part of a new session. Otherwise, every time there is an interaction, the expiration time is extended by adding these additional minutes.</td>
</tr>
<tr>
<td><code>trackYouTubeVideos</code></td>
<td>No</td>
<td>Boolean</td>
<td>

Enable tracking of YouTube videos. For more information, see [Track Interactions with YouTube videos](https://www.progress.com/documentation/sitefinity-cms/insight/track-interactions-with-youtube-videos-2).

</td>
</tr>
<tr>
<td><code>trackVimeoVideos</code></td>
<td>No</td>
<td>Boolean</td>
<td>

Enable tracking of Vimeo videos. For more information, see [Track Interactions with Vimeo videos](https://www.progress.com/documentation/sitefinity-cms/insight/track-interactions-with-vimeo-videos).

</td>
</tr>
<tr>
<td><code>useSecureCookies</code></td>
<td>No</td>
<td>Boolean</td>
<td>

Default: `true`. When set to `false`, the tracking cookie will be issued with parameter `SameSite=Lax` over https connections.\
For more information, see [Manage cookies](https://www.progress.com/documentation/sitefinity-cms/insight/manage-cookies) » *Additional cookie configuration*.

</td>
</tr>
</tbody>
</table>

## Start the SDK

After you have registered the callback, download and execute the Insight SDK.

To do this, in the `<head>` tag, add the following `<script>` tag:

```HTML
<script type="text/javascript" src="https://cdn.insight.sitefinity.com/sdk/sitefinity-insight-client.min.3.1.44.js" async></script>
```
