iOS相关技术实现

iOS开发之对接第三方打点

2018-03-12  本文已影响1096人  KODIE

概要

我现在的打点需求主要是负责海外市场,所以用的打点第三方是AF和FB,也就是AppsFlyer和Facebook的应用分析功能

对接Facebook的应用分析功能

Facebook Analytics Quickstart Guide for iOS

应用分析接口入口

步骤:
①选择一个应用接入分析功能


Snip20180312_3.png

②设置开发环境,下载SDK或者cocoapods,然后在AppDelegate.m文件中添加头文件,然后添加如下代码:

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}

③在FB应用中绑定BundleId:


Snip20180312_5.png

④在info.plist文件中添加如下源码:


<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>fb8217****66**0</string>
  </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>8217****66**0</string>
<key>FacebookDisplayName</key>
<string>AFAndFTestBTestDemo</string>

其中8217****66**0为你的FB应用编号,请填写真实的应用编号,一般在第一步选择了应用或者新增了应用,下面会这段XML源码会自动生成的
⑤接下来就是新建项目,然后添加应用事件了,其中添加应用事件按照应用分析接口入口这个来接就好了。

所需参数:
①FB上应用编号
②FB上应用名称
③打点key

注意问题:

①查看数据:


Snip20180312_8.png

②如果要看到测试数据,先加上开启调试测试代码,在AppDelegate中didFinishLaunch方法中添加:

[FBSDKSettings enableLoggingBehavior:FBSDKLoggingBehaviorAppEvents];

③一般测试会有点延迟看到效果,另外如果过了一段时间还没有,那么请开启VPN,因为Facebook毕竟被墙了。

④如果还没有的话,试试添加开发者,然后在你的设备上登录FB,然后再打开应用测试,一般这一步是不要的。如果还没有数据那可能真的是你前面配错了...

对接AppsFlyer

SDK集成相关
iOS - 最新SDK对接文档
iOS应用 - AppsFlyer SDK接入测试

接入步骤:
①下载Framework或者cocoapods
点此下载Framework

pod ‘AppsFlyerFramework’

②在工程项目中添加如下头文件

#import <AppsFlyerTracker/AppsFlyerTracker.h>

③添加如下库:

AdSupport.framework
 iAd.framework

④初始化SDK

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //这个可以在AppsFlyer后台找到
    [AppsFlyerTracker sharedTracker].appsFlyerDevKey = @"a4kGpVyxm8iGgzvzT8NPaV";
    //这个填的是商店的iTunesID
    [AppsFlyerTracker sharedTracker].appleAppID = @"123456789";
    return YES;
}
//这种从info.plist文件中读取
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self initAppsFlyerTracker];
    return YES;
}
- (void)initAppsFlyerTracker{
    NSString *appsFlyerId = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"AppsFlyerId"];
    NSString *appsFlyerKey = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"AppsFlyerKey"];
    if (appsFlyerId == nil || appsFlyerId.length <=0 || appsFlyerKey == nil || appsFlyerKey.length <= 0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AppsFlyerId or AppsFlyerKey id is empty" message:@"" delegate:nil cancelButtonTitle:@"confirm" otherButtonTitles: nil];
        [alert show];
        return ;
    }
    //这个可以在AppsFlyer后台找到
    [AppsFlyerTracker sharedTracker].appsFlyerDevKey = appsFlyerKey;
    //这个填的是商店的iTunesID
    [AppsFlyerTracker sharedTracker].appleAppID = appsFlyerId;
}

⑤追踪应用打开

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [[AppsFlyerTracker sharedTracker] trackAppLaunch];
}

⑥应用事件追踪

- (void) trackEvent:(NSString *)eventName withValues:(NSDictionary*)values

eventName是一个任意的字符串,代表事件名称。

    * 事件名称不能超过45个字符,否则该事件将不会出现在后台,只会出现在原始数据报告,以及Push和Pull API返回的数据中

values是一个包含该事件所有可能值的字典类型 (NSDictionary*)

    * 事件的值可以为0个,1个,或多个
***富应用内事件收益**:请使用“af_revenue”(常数)*
AFEventParamRevenue
其可为任何数值,正负均可。

***注意***:如果有些收益您不希望记录在控制面板中的Revenue中,可使用“af_price”

AFEventParamPrice
不会作为revenue进行记录,因此不会影响收益的记录以及LTV的监测。

点击这里了解AppsFlyer富应用内事件(iOS)的详情。下面给出几个富应用内事件的例子

例子:
示例1:游戏过关事件

[[AppsFlyerTracker sharedTracker] trackEvent: AFEventLevelAchieved withValues:@{    
   AFEventParamLevel: @9,
   AFEventParamScore : @100 }];

这段代码将创建一个”af_level_achieved”事件,对应事件的值为:

{af_level: 9 , af_score: 100}

示例2:付费事件

[[AppsFlyerTracker sharedTracker] trackEvent:AFEventPurchase withValues: @{
   AFEventParamContentId:@"1234567",
   AFEventParamContentType : @"category_a",
   AFEventParamRevenue: @200,
   AFEventParamCurrency:@"USD"}];

这段代码将创建一个”af_purchase”事件,对应的值为:

{af_content_id: “1234567”, af_content_type: “category_a”, af_revenue: 200, af_currency: “USD”}

注意,您在任何事件中包含的AFEventParamRevenue (af_revenue)类型的变量,都会被我们单独统计,并作为Revenue显示在后台和报表中。其他变量类型的值都不会影响Revenue的统计。

更多高级设置请见:iOS - 最新SDK对接文档

高级设置(可选)

以下的API属于AppsFlyer的高级设置,请根据需要选用

  1. 设置货币单位

AppsFlyer默认的货币单位是美元(USD)。以下代码可以设置全局的货币单位,对应的ISO代码可以从这里找到

[[AppsFlyerTracker sharedTracker].currencyCode = @"GBP"];

注意,您可以在af_purchase事件中,通过“af_currency” (AFEventParamCurrency),单独为该事件的revenue指定货币单位*

2. 获取AppsFlyer ID

AppsFlyer ID是AppsFlyer对于某个app的新用户赋予的唯一ID,它被用于在系统内部标识某个app的独立用户,出现在所有原始数据报表和API中。你可以通过以下的代码获取该ID:

(NSString *) [AppsFlyerTracker sharedTracker] getAppsFlyerUID

3. 设置广告主的用户ID

如果你有自己的用户系统,把你们的用户ID发送给AppsFlyer,可以轻松实现跨应用,跨平台的用户追踪,以及把AppsFlyer的广告投放效果整合到广告主的BI系统中。设置广告主用户ID的代码如下:

[[AppsFlyerTracker sharedTracker].customerUserID = @"YOUR_CUSTOM_DEVICE_ID"];

所需参数:
①iTunes上应用id
②AppsFlyer上的key
③打点key

注意:

更多关于广告主用户ID的详情,请参考这个文档

测试数据请见测试文档!

以上!!!

呆萌.png
上一篇 下一篇

猜你喜欢

热点阅读