// the client is available via CocoaPods, just add this to your Podfile
pod 'stream-analytics-ios'
Setup
The code below shows how to install Stream’s Analytics SDK:
// download the latest release from here: https://github.com/GetStream/stream-analytics-android/releases/
// 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>
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: "{{ 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 }}"
});
// 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
// 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);
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");