开发指南
介绍
TapSDK 提供了一套可供游戏开发者收集账号数据的 API。 系统会收集账号数据并进行分析,最终形成数据报表,帮助游戏开发者分析账号行为并优化游戏。
SDK 获取
请先下载 SDK,并添加相关依赖 .
如果只需要单独使用 TapDB,可以只依赖 common+tapdb
- Unity
- Android
- iOS
"dependencies":{
// 登录
"com.taptap.tds.login":"https://github.com/TapTap/TapLogin-Unity.git#2.1.8",
"com.taptap.tds.common":"https://github.com/TapTap/TapCommon-Unity.git#2.1.8",
"com.taptap.tds.bootstrap":"https://github.com/TapTap/TapBootstrap-Unity.git#2.1.8",
// 数据分析
"com.taptap.tds.tapdb": "https://github.com/TapTap/TapDB-Unity.git#2.1.8",
}
repositories{
flatDir {
dirs 'libs'
}
}
dependencies {
...
implementation (name:'TapBootstrap_2.1.8', ext:'aar') // 必选: TapSDK 启动器
implementation (name:'TapCommon_2.1.8', ext:'aar') // 必选:TapSDK 基础库
implementation (name:'TapLogin_2.1.8', ext:'aar') // 必选:TapTap 登录
implementation (name:'TapDB_2.1.8', ext:'aar') // 数据统计
}
// 登录
TapBootstrapSDK.framework
TapCommonResource.bundle
TapLoginResource.bundle
TapCommonSDK.framework
TapLoginSDK.framework
//TapDB
TapDB.framework
初始化 SDK
info
以下两种初始化方式结合使用场景任选其一即可。
TapSDK 初始化
在 TapSDK 初始化时,同步初始化 TapDB。
- Unity
- Android
- iOS
TapConfig tapConfig = new TapConfig.Builder()
.ClientID("clientId")// 必须
.ClientSecret("client_secret")// 必须
.RegionType(RegionType.CN)// 非必须,默认 CN
.TapDBConfig(true, "gameChannel", "gameVersion", true) // TapDB 会根据 TapConfig 的配置进行自动初始化
.ConfigBuilder();
TapBootstrap.Init(tapConfig);
TapDBConfig tapDBConfig = new TapDBConfig();
tapDBConfig.setEnable(true);
tapDBConfig.setChannel("gameChannel");
TapConfig tapConfig = new TapConfig.Builder()
.withAppContext(getApplicationContext())
.withRegionType(TapRegionType.CN) // TapRegionType.CN: 国内 TapRegionType.IO: 国外
.withClientId("clientId")
.withClientSecret("clientSecret")
.withTapDBConfig(tapDBConfig)
.build();
TapBootstrap.init(MainActivity.this, tapConfig);
// 初始化 SDK
TapConfig *config = TapConfig.new;
config.clientId = @"clientId";
config.clientSecret=@"clientSecret";
TapDBConfig * dbConfig = [[TapDBConfig alloc]init];
dbConfig.enable = YES;
dbConfig.channel=@"taptap";
dbConfig.gameVersion=@"1.0.0";
dbConfig.advertiserIDCollectionEnabled=YES;
config.dbConfig = dbConfig;
config.region = TapSDKRegionTypeCN;
[TapBootstrap initWithConfig:config];
TapDB 单独使用
在单独使用 TapDB 功能时(即不接登录功能时,不导入 TapBootstrap 包时),可以通过以下方式初始化 TapDB。
- Unity
- Android
- iOS
TapDB.Init("clientId", "taptap", "gameVersion", true);
TapDB.init(getApplicationContext(), "clientId", "taptap", "gameVersion", true);
[TapDB onStartWithClientId:@"clientid" channel:@"taptap" version:@"gameVersion" isCN:YES];
上述代码示例中,clientId 可以在控制台获取,taptap 为分包渠道(游戏安装包渠道),gameVersion 为游戏版本号,最后一个参数表示区域,true 表示中国大陆,false 表示国际。
分包渠道和游戏版本号的长度不大于 256,可以为 null。
分包渠道为 null 时,就无法根据渠道筛选收集到的数据了。
游戏版本号为 null 时,TapSDK 会自动获取游戏安装包的版本。
设置获取 IDFA
针对 iOS14.5+,可以设置是否获取 IDFA。
默认不获取 IDFA,如果设置获取 IDFA,还需要在应用层额外配置相关弹窗权限。
- Unity
- Android
- iOS
TapDB.AdvertiserIDCollectionEnabled(true);
// Android 平台不适用
[TapDB setAdvertiserIDCollectionEnabled:YES];
设置账号
调用该 API 记录一个账号,当账号登录时调用。
- Unity
- Android
- iOS
TapDB.SetUser("userId");
TapDB.setUser("userId");
[TapDB setUser:@"userId"];
userId 是代表账号的唯一字符串,字符串长度不大于 256,只能包含数字、大小写字母、下划线(_)、短横(-)。
开发者需要保证不同账号的 userId 均不相同。
账号昵称
游戏设置账号昵称时调用。
- Unity
- Android
- iOS
TapDB.SetName("Tarara");
TapDB.setName("Tarara");
[TapDB setName:@"Tarara"];
参数的类型为字符串,不可为空,长度不大于 256。
账号等级
设置账号等级,通常在账号升级时调用。
- Unity
- Android
- iOS
TapDB.SetLevel(5);
TapDB.setLevel(5);
[TapDB setLevel:5];