数据统计接口文档

数据统计接口文档

1 初始化启动接口

接口描述:

使用统计功能以前,需要先启动 SDK,该接口用于在 App 运行时启动数据统计 SDK。

接口定义:

/**
 初始化启动接口

 @param appId 开发者中心生成的 appId
 @param channelId 渠道名称,默认为 'appstore'
 */
+ (void)startSDKWithAppId:(NSString *)appId withChannelId:(NSString *)channelId;

接口说明:

AppDelegate didFinishLaunchingWithOptions 方法中:通过平台分配的 APPID 启动统计 SDK。

参数 参数说明
appId 应用标识 APPID
channelId 渠道名称,如果为 nil或者空串,默认为 'appstore'

接口示例:

#import <GTCountSDK/GTCountSDK.h>
#define kGcAppId @"xxxxxxx"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   // 启动数据统计 SDK
   [GTCountSDK startSDKWithAppId:kGcAppId withChannelId:@"appstore"];
   return YES;
 }

2 获取gtcid

接口描述:

您可通过下面的方法获取gtcid,gtcid可用于用户画像标签的查询。

接口定义:

/// gtcid可用于用户画像标签的查询。
+ (NSString*)gtcid;

接口示例:

NSLog(@"gtcid:%@", [GTCountSDK gtcid]);

3 次数统计事件

接口描述:

在事件执行开始时调用次数统计方法,SDK 会根据事件 Id ,统计该事件被点击的次数。

接口定义:

/**
 计数事件统计

 @param eventId 事件 Id
 @param args 自定义属性,key 必须为 NSString 类型(注意:不能以$开头),value 仅支持NSNumber, BOOL, NSString, NSDate 4 种类型
 @param ext 自定义ext字段内容。
 */
+ (void)trackCountEvent:(NSString *)eventId withArgs:(NSDictionary *)args withExt:(NSString *)ext;

接口参数说明:

参数 参数说明
eventId 自定义事件 Id
args ⾃定义属性,key 必须为 NSString 类型(注意:不能以$开头),value 仅支持NSNumber, BOOL, NSString, NSDate 4 种类型
ext 自定义ext字段内容

接口示例:

@implementation TrackCountEventController
 - (IBAction)clickCount:(id)sender {
   [GTCountSDK trackCountEvent:@"test" withArgs:@{@"time":[NSDate date],@"number":@(34.0),@"string":@"str",@"BOOL":@YES} withExt:nil];
 }
 @end

4 时长统计事件

接口描述:

在事件开始和结束时调用对应方法,可以获取并上传事件的时长。

接口定义:

/**
 记录自定义事件的开始
 注意:需要跟 trackCustomKeyValueEventEnd:withArgs: 配对使用
 若多次调用则以最后一次开始的时间为准

 @param eventId 自定义事件 Id
 */
+ (void)trackCustomKeyValueEventBegin:(NSString *)eventId;

/**
 记录自定义事件的结束
 注意:需要跟 trackCustomKeyValueEventBegin: 配对使用
 若多次调用则以第一次结束的时间为准

 @param eventId 自定义事件 Id
 @param args 自定义属性,key 必须为 NSString 类型(注意:不能以$开头),value 仅支持NSNumber, BOOL, NSString, NSDate 4 种类型。
 @param ext 自定义ext字段内容。
 */
+ (void)trackCustomKeyValueEventEnd:(NSString *)eventId withArgs:(NSDictionary *)args withExt:(NSString *)ext;

接口参数说明:

参数 参数说明
eventId 自定义事件 Id
args 自定义属性,用于扩展统计需要
ext 自定义ext字段内容

接口示例:

 @interface TrackCustomKeyValueEventController ()
 @end

 @implementation TrackCustomKeyValueEventController
 -(void) viewDidAppear:(BOOL)animated {
     [GTCountSDK trackCustomKeyValueEventBegin:@"eid1"];
     [super viewDidAppear:animated];
 }
 - (void)viewWillDisappear:(BOOL)animated {
     [GTCountSDK trackCustomKeyValueEventEnd:@"eid1" withArgs:@{@"time":[NSDate date],@"number":@(34.0),@"string":@"str",@"BOOL":@YES} withExt:nil];
     [super viewWillDisappear:animated];
 }
@end

5 用户属性设置

接⼝描述:

设置用户属性,记录的是用户的基本固定不变的属性,例如性别、出生年份、注册时间、注册地域、注册渠道等。

接⼝定义:

/**
 用户属性设置

 @param profiles 用户属性参数,key 必须为 NSString 类型,value 仅支持NSNumber, BOOL, NSString, NSDate 4 种类型
 @param ext 自定义ext字段内容。
 */
+ (void)setProfile:(NSDictionary *)profiles withExt:(NSString *)ext;
+ (void)setProfile:(NSDictionary *)profiles;

接⼝示例:

NSMutableDictionary *profiles = [NSMutableDictionary new]; 
[profiles setObject:@"username001" forKey:@"$name"]; 
[profiles setObject:@"男" forKey:@"$sex"];
[GTCountSDK setProfile:profiles.copy];
return YES;

6 设置会话超时时长

接口描述:

设置会话时长(默认 30000 ms,单位毫秒),在应用退到后台后停留时间超过会话时长,视为一次新的应用会话。

接口定义:

/**
 设置会话时长(默认 30000 ms,单位毫秒),在应用退到后台后停留时间超过会话时长,视为一次新的应用会话。
 */
@property (nonatomic, assign)NSUInteger sessionTime;

接口示例:

#import <GTCountSDK/GTCountSDK.h>
#define kGcAppId @"xxxxxxx"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   [GTCountSDK sharedInstance].sessionTime = 30*1000;
   [GTCountSDK startSDKWithAppId:kGcAppId withChannelId:@"appstore"];
   return YES;
 }

7 设置有效活跃时长

接口描述:

设置有效活跃时长,活跃时长满足[min, max]的才会上报服务器记录。

接口定义:

/**
 设置有效活跃时长,活跃时长满足[min, max]的才会上报服务器记录
 minAppActiveDuration默认 1000 ms, maxAppActiveDuration默认 12*3600*1000 ms, 单位毫秒
 */
@property (nonatomic, assign) NSInteger minAppActiveDuration;
@property (nonatomic, assign) NSInteger maxAppActiveDuration;

接口示例:

#import <GTCountSDK/GTCountSDK.h>
#define kGcAppId @"xxxxxxx"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [GTCountSDK sharedInstance].minAppActiveDuration = 1000;
    [GTCountSDK sharedInstance].maxAppActiveDuration = 12*3600*1000;
    [GTCountSDK startSDKWithAppId:kGcAppId withChannelId:@"appstore"];
   return YES;
 }

8 设置事件上传频率

接口描述:

时长统计事件和次数统计事件累计条数到达ForceUploadSize 或 距离上一次汇报时间间隔超过UploadInterval后,将触发上传流程。

接口定义:

/**

// trackCustomKeyValueEvent和trackCountEvent的上报间隔, 默认10000毫秒,即10秒
@property (nonatomic, assign) NSInteger eventUploadInterval;

// trackCustomKeyValueEvent和trackCountEvent 的上报条数阈值,默认30
@property (nonatomic, assign) NSInteger eventForceUploadSize;

接口示例:

#import <GTCountSDK/GTCountSDK.h>
#define kGcAppId @"xxxxxxx"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [GTCountSDK sharedInstance].eventUploadInterval = 10000;
    [GTCountSDK sharedInstance].eventForceUploadSize = 30;
    [GTCountSDK startSDKWithAppId:kGtAppId withChannelId:@""];
   return YES;
 }

9 设置Profile上报频率

接口描述:

SetProfile累计条数到达ForceUploadSize 或 距离上一次汇报时间间隔超过UploadInterval后,将触发上传流程。

接口定义:

/**

// Profile上报间隔, 默认5000毫秒,即5秒
@property (nonatomic, assign) NSInteger profileUploadInterval;

// Profile上报条数阈值,默认5
@property (nonatomic, assign) NSInteger profileForceUploadSize;

接口示例:

#import <GTCountSDK/GTCountSDK.h>
#define kGcAppId @"xxxxxxx"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [GTCountSDK sharedInstance].profileUploadInterval = 5000;
    [GTCountSDK sharedInstance].profileForceUploadSize = 5;
    [GTCountSDK startSDKWithAppId:kGtAppId withChannelId:@""];
   return YES;
 }

10 设置App Groups ID

接口描述:

通过苹果开发者后台创建Group Identify, 用于App主包和Extension之间的数据打通。

接口定义:

+ (void)setApplicationGroupIdentifier:(NSString*)identifier;

接口示例:

主包AppDelegate.m文件:

#import <GTCountSDK/GTCountSDK.h>
#define kGcAppId @"xxxxxxx"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //设置主包GroupId
    [GTCountSDK setApplicationGroupIdentifier:@"group.ent.com.getui.demo"];
    [GTCountSDK startSDKWithAppId:kGtAppId withChannelId:@""];
   return YES;
 }

Widget小组件swift文件:

func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
    var entries: [SimpleEntry] = []
    //设置小组件GroupId
    GTCountSDK.setApplicationGroupIdentifier("group.ent.com.getui.demo")
    GTCountSDK.start(withAppId: kGtAppId, withChannelId: "widget")
}

文档中心搜索

技术
咨询

微信扫一扫

随时联系技术支持

在线
咨询