// download the latest release from here: https://github.com/GetStream/stream-analytics-android/releases/You are viewing the Feeds v2 documentation. Feeds v2 is in maintenance mode and no longer receives new features. New projects should use Feeds v3, a major upgrade in performance, capabilities, and developer experience. To move an existing app, follow the migration guide.
Setup
The code below shows how to install Stream's Analytics SDK:
Include the above code snippet in the <head></head> section of your page.
JavaScript is loaded asynchronously for optimal performance.
Using CommonJS Modules
If you're using CommonJS modules, run the following command in your project directory:
npm install stream-analytics --saveAfter installing the package, require it in your app:
const StreamAnalytics = require("stream-analytics");Client Setup
The snippet below shows you how to initialize Stream's analytics client:
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 :
<uses-permission android:name="android.permission.INTERNET" />Always specify the current user before sending events:
// user id and a friendly alias for easier to read reports
client.setUser({ id: 486892, alias: "Julian" });