Setup

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'

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:

// Initialize StreamAnalytics in AppDelegate

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

@interface AppDelegate ()
@end

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

Bind the service in your application’s manifest.xml :

<uses-permission android:name="android.permission.INTERNET" />

Always specify the current user before sending events:

#import "Stream.h"

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

// add friendly alias for the user
[[StreamAnalytics sharedInstance] setUserId:@"486892" andAlias:@"Julian"];
© Getstream.io, Inc. All Rights Reserved.