Last Edit: Jul 31 2020

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

// the client is available via CocoaPods, just add this to your Podfile

pod 'stream-analytics-ios'

// download the latest release from here:

// Add this async loader code anywhere in your HTML code

<script type="text/javascript">
  !function(t,e){t("StreamAnalytics", "", 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);

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 --save

After 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: "YOUR_API_KEY",

// Initialize StreamAnalytics in AppDelegate

#import "AppDelegate.h"
#import "Stream.h"

@interface AppDelegate ()

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //enable debug logging
    [StreamAnalytics enableLogging:YES];
    return YES;

// 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("YOUR_API_KEY","ANALYTICS_TOKEN");
StreamAnalytics client = StreamAnalyticsImpl.getInstance(auth);

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' });

#import "Stream.h"

// set user id only 
[[StreamAnalytics sharedInstance] setUserId:@"486892"];

// add friendly alias for the user
[[StreamAnalytics sharedInstance] setUserId:@"486892" andAlias:@"Julian"];

// set user data
client.setUser("486892", "Eric");

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