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

<Tabs>

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

</Tabs>

### Client Setup

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

<Tabs>

```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 }}",
});
```

```kotlin label="Kotlin"
// Import the library in your Gradle project:

dependencies {
 compile files('/path_to_file/stream-analytics-release-1.1.0.aar')
}

// Initialize the StreamAnalytics client
StreamAnalyticsAuth auth = new StreamAnalyticsAuth("{{ api_key }}","{{ analytics_token }}");
StreamAnalytics client = StreamAnalyticsImpl.getInstance(auth);
```

</Tabs>

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:

<Tabs>

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

```kotlin label="Kotlin"
// set user data
client.setUser("486892", "Eric");

// you can also set the userId only
// client.setUserId("486892");
```

</Tabs>


---

This page was last updated at 2026-04-20T22:48:03.320Z.

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