# Setup

The code below shows how to install Stream's Analytics SDK:

<Tabs>

```kotlin label="Kotlin"
// download the latest release from here: https://github.com/GetStream/stream-analytics-android/releases/
```

```html label="HTML"
// Add this async loader code anywhere in your HTML code

<script type="text/javascript">
  !(function (t, e) {
    t(
      "StreamAnalytics",
      "https://d2j1fszo1axgmp.cloudfront.net/2.7.0/stream-analytics.min.js",
      e,
    );
  })(function (t, e, n) {
    var s, i, r;
    ((n["_" + t] = {}),
      (n[t] = function (e) {
        ((n["_" + t].clients = n["_" + t].clients || {}),
          (n["_" + t].clients[e.apiKey] = this),
          (this._config = e));
      }));
    var c = function (t) {
      return function () {
        return (
          (this["_" + t] = this["_" + t] || []),
          this["_" + t].push(arguments),
          this
        );
      };
    };
    s = ["setUser", "trackImpression", "trackEngagement"];
    for (var a = 0; a < s.length; a++) {
      var o = s[a];
      n[t].prototype[o] = c(o);
    }
    ((i = document.createElement("script")),
      (i.async = !0),
      (i.src = e),
      (r = document.getElementsByTagName("script")[0]),
      r.parentNode.insertBefore(i, r));
  }, this);
</script>
```

</Tabs>

Include the above code snippet in the  `<head></head>`  section of your page.

<Admonition type="info">

JavaScript is loaded asynchronously for optimal performance.

</Admonition>

### Using CommonJS Modules

If you're using CommonJS modules, run the following command in your project directory:

<Tabs>

```bash label="Bash"
npm install stream-analytics --save
```

</Tabs>

After installing the package, require it in your app:

```js label="JavaScript"
const StreamAnalytics = require("stream-analytics");
```

### Client Setup

The snippet below shows you how to initialize Stream's analytics client:

```js label="JavaScript"
const client = new StreamAnalytics({
  apiKey: "{{ api_key }}",
  token: "{{ analytics_token }}",
});

// Above snippet uses US by default, you can also set to other regions.
// dublin
const client = new StreamAnalytics({
  baseUrl: "https://dublin-analytics.stream-io-api.com/analytics/v1.0/",
  apiKey: "{{ api_key }}",
  token: "{{ analytics_token }}",
});
```

Bind the service in your application's  `manifest.xml` :

<Tabs>

```xml label="XML"
<uses-permission android:name="android.permission.INTERNET" />
```

</Tabs>

Always specify the current user before sending events:

```js label="JavaScript"
// user id and a friendly alias for easier to read reports
client.setUser({ id: 486892, alias: "Julian" });
```


---

This page was last updated at 2026-08-07T20:37:31.055Z.

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/javascript/v2/analytics-setup/](https://getstream.io/activity-feeds/docs/javascript/v2/analytics-setup/).