fastream-ios-sdk 0.0.9

fastream-ios-sdk 0.0.9

Łukasz SzymańczukPatryk WojtyńskiŁukasz Szymańczuk 维护。



  • By
  • Fastream

Fastream-iOS-SDK - iOS 事件跟踪库

Version License Platform

安装

使用 CocoaPods Can be integrated with the Fastream-iOS library in a few simple steps.

安装 CocoaPods

  1. 打开终端并运行 sudo gem install cocoapods
  2. 运行 pod setup

在项目中集成 Fastream-iOS 库

  1. 在您的项目根目录下创建一个名为 Podfile 的文件
  2. 将以下行添加到您的 Podfile 中
pod "fastream-ios-sdk"
  1. 关闭 Xcode
  2. 打开终端,并在您的项目根目录中运行 pod install
  3. 打开新的 Xcode 工作区(<your-project>.xcworkspace

兼容性

Fastream-iOS库是Mixpanel-iphone库的一个修改版,缩减到仅必要的事件跟踪。

要集成Fastream-iOS,您需要使用Xcode 5和一个iOS 7.0的Base SDK。该库可以与iOS 6.0及以上的部署目标一起工作。

初始化

要使用Fastream-iOS库,您必须首先用您的Fastream端点的主机名和令牌初始化它。由于这应该只做一次,因此在应用程序完成启动时初始化Fastream-iOS是有意义的

#import <fastream_ios_sdk/Fastream.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    /* ... */
    
    NSString *token = @"YOUR-TOKEN";
    NSString *url = @"YOUR-URL";
    [Fastream sharedInstanceWithToken:token serverURL:url];
    
    return YES;
}

初始化后,您可以通过调用sharedInstance方法,在您的代码的任何地方使用Fastream-iOS库

    Fastream *Fastream = [Fastream sharedInstance];

发送事件

要向Fastream发送事件,您可以选择遵循Mixpanel的track:properties:约定,或者使用更自由的trackCustomEvent:来发送JSON可序列化的NSDictionary对象。

Mixpanel的方法

如我们所述,Fastream-iOS是从Mixpanel分叉的,因此它支持由Mixpanel库实现的全部方法

  • track
  • track:properties
  • timeEvent
  • registerSuperProperties: & registerSuperPropertiesOnce:
  • identify
  • flush & reset

以下代码可以实现基本事件跟踪

Fastream *Fastream = [Fastream sharedInstance];

// Track an event just with a type
[Fastream track:@"Event-type1"];

// Track an event with a type & properties
[Fastream track:@"Event-type2" properties:@{
    @"prop1": @"abc",
    @"prop2": 123
}];

使用这些方法将发送以下格式的事件

{
    "event": "Event-type2",
    "properties": {
        "prop1": "abc",
        "prop2": 123,
        /* 
           additional properties added by the library:
           distinct_id, $os, time, sending_time, $model
           $manufacturer, $wifi, $screen_width, 
           $screen_height, ...
        */
    }
}

有关Mixpanel提供其他函数的文档,请参阅Mixpanel网站

自定义方式

如果您尚未使用Mixpanel,并且只想发送自定义JSON对象,可以使用以下片段

Fastream *Fastream = [Fastream sharedInstance];

[Fastream trackCustomEvent:@{
    @"custom-field1": @"event-type",
    @"custom-field2": @"abc",
    @"custom-field3": 123
}];

使用该方法将发送事件,格式如下

{
    "custom-field1": "event-type",
    "custom-field2": "abc",
    "custom-field3": 123,
    "properties": {
        /* 
           additional properties added by the library:
           distinct_id, $os, time, sending_time, $model
           $manufacturer, $wifi, $screen_width, 
           $screen_height, ...
        */
    }
}

一般说明

  • Fastream-iOS会为每个事件添加额外的属性

    • time - 事件跟踪时的纪元时间(秒)
    • sending_time - 实际发送事件时的纪元时间(秒)(如果设备离线)
    • distinct_id - 唯一标识符,用于识别设备
    • 其他字段及其值可以在collectAutomaticProperties函数中查看
  • Fastream-iOS将事件存储在内部事件队列中,以在线时发送。该队列大小固定为500个事件。如果设备离线且队列填满,第501个事件将导致第1个(最古老)的事件从队列中弹出并丢弃。

使用示例应用进行测试

要运行示例项目,请克隆仓库,然后从示例目录运行pod install。打开SampleApp.xcworkspace并运行应用程序。

作者

Fastream [email protected]

许可协议

Fastream-iOS在Apache v2许可证下提供。有关更多信息,请参阅LICENSE文件。