重要!

oneLink要求:

  • 市场sdk初始化接口必须要放到ApplicationonCreate函数中调用
  • 否则收不到邀请链接数据
  • 如果未在ApplicationonCreate函数中进行初始化,请更改调用位置

# 1 功能介绍

本文将介绍如何快速接入appflyer OneLink 功能。

完成本文接口功能,你可以实现:

  • OneLink基本配置
  • 生成邀请链接
  • 获取邀请透传信息

# 2 前置条件

  1. 以下所有api调用com.hero.market.MarketSDK类来操作

  2. 使用此功能之前请确保已经完成市场SDK appflyer相关SDK配置

  3. 已经在appflyer后台创建了 OneLink 模板详细文档链接 (opens new window)

  4. 创建OneLink模板以后获取到 模板ID (Template ID)

# 3 接入步骤

# 3.1 AndroidManifest.xml配置

  • 配置位置:游戏主(Launcher) Activity节点下

  • OneLink Android链接方式

    • 示例如下:

        <intent-filter  android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https"
                android:host="gostars.onelink.me"
                android:pathPrefix="/6alo" />
        </intent-filter>
      
      1
      2
      3
      4
      5
      6
      7
      8
    • 将后台申请得到的配置 覆盖 以上配置

      • 获取位置如图所示:

  • OneLink URL scheme方式

    • 示例如下:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="mainactivity"
                android:scheme="gostars" />
        </intent-filter>
      
      1
      2
      3
      4
      5
      6
      7
      8
    • 把以上配置复制到launcher节点,并修改data节点下的 hostscheme 与appflyer后台自定义的字段对应

      • host 与 scheme不要有特殊字符, 增加 特殊标记 避免与他人游戏冲突

      • host 对应一下截图里面的 mainactivity ,scheme对应 gostars (值均为自定义)

      • 获取位置截图如下:

  • 以上两种方式都需要添加,最终示例位置如下:

    <activity
        //这里的类名只是示例,最终对应到游戏主activity
        android:name="com.appsflyer.onelink.appsflyeronelinkbasicapp.MainActivity"
        android:launchMode="singleTask">
    
        //launcher 页面标识
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    
    
        // OneLink Android链接方式
        <intent-filter  android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https"
                android:host="gostars.onelink.me"
                android:pathPrefix="/6alo" />
        </intent-filter>
    
        //OneLink URL scheme方式
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="mainactivity"
                android:scheme="gostars" />
        </intent-filter>
    </activity>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

# 3.2 初始化传递templateId

说明

在市场sdk初始化方法之前添加配置信息

示例

  MkConfig config = new MkConfig();
  ...

  //设置AppsFlyer devkey 与 templateid
  config.putThirdExtra(ThirdExtraKey.AF_DEV_KEY, "jCzv8jt*********bhMPYE");
  config.putThirdExtra(ThirdExtraKey.TEMPLATE_ID, "templateId");

  ...
1
2
3
4
5
6
7
8

华丽分割线 ---如果只是需要使用AF后台Onelink链接进行点击跳转打开游戏,接入到这里就可以了,后面的内容不用接入


# 3.3 获取邀请链接

场景介绍 如果需要根据不同玩家自定义邀请链接参数,并且记录邀请人,那么可以使用此接口生成实时的链接,以供玩家分享使用

前置条件 该接口需在市场SDK初始化完成以后进行调用

接口声明

public static void getAppsflyerOneLinkUrl(Activity activity, Bundle bundle, OnResultListener onResultListener)
1

参数说明

字段 类型 重要性 说明
activity Activity 必须 activity实例
bundle Bundle 必须 参数包装
onResultListener OnResultListener 必须 回调结果

调用示例

    Bundle bundle = new Bundle();
    bundle.putString(ThirdExtraKey.DEEP_LINK_VALUE, "自定义值");//被推荐用户应该深入链接到的应用体验
    bundle.putString(ThirdExtraKey.DEEP_LINK_SUB1, "自定义值");//受邀者收到的促销代码。
    bundle.putString(ThirdExtraKey.DEEP_LINK_SUB2, "自定义值");//推荐人标识符。可用于奖励推荐人。
    //以上三个字段在被邀请人进入游戏后都会返回
    MarketSDK.getAppsflyerOneLinkUrl(MainActivity.this, bundle, new OnResultListener() {
        @Override
        public void onSuccess(String result) {
            //获取到result,即Url
        }

        @Override
        public void onError(String error) {
            //如果获取失败,这里有相应日志返回(此错误信息均为appsflyer返回,SDK只是中转)
        }
    });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

特别说明

如果对返回字段不明白的,可以直接查看 appsflyer邀请文档 (opens new window)

# 3.4 记录邀请链接创建事件

背景介绍

  • 为方便appsflyer后台事件记录,appsflyer开发文档要求获取到邀请链接之后,上报一下邀请事件 af_invite

  • 让研发自己上报的原因是研发朋友可以根据运营对事件需求,自定义一些参数信息

调用位置

获取到邀请链接即可调用

接口声明

public static void sendAppsflyerEvent(String event, Bundle values)
1

参数说明

字段 名称 重要性 类型 说明
event String 必须 事件名 针对邀请事件,此值填写af_invite
values String 可选 -

调用示例

Bundle bundle = new Bundle();
bundle.putString("referrerId", <REFERRER_ID>);
MarketSDK.sendAppsflyerEvent("af_invite", bundle);
1
2
3

appsflyer对邀请事件的说明

# 3.5 获取OneLink返回值

场景介绍

  • 玩家通过邀请链接 下载/打开 游戏以后,通过appsflyer接口返回参数信息(生成链接时候传递的参数信息)

  • 务必在进入游戏主activity后调用,否则可能获取到空值 (研发要进行空值判断,以免闪退)

接口声明

public static Bundle getAppsflyerOneLinkData(Activity activity)
1

调用示例

    Bundle bundle = MarketSDK.getAppsflyerOneLinkData(MainActivity.this);
    if(bundle != null){
        String deep_link_value = bundle.getString(ThirdExtraKey.DEEP_LINK_VALUE);
        String deep_link_sub1 = bundle.getString(ThirdExtraKey.DEEP_LINK_SUB1);
        String deep_link_sub2 = bundle.getString(ThirdExtraKey.DEEP_LINK_SUB2);
        //处理对应操作
    }
1
2
3
4
5
6
7

# 3.6 生命周期

场景介绍

  • 避免游戏主activity不是标准启动模式,获取不到邀请信息,所以必须调用此生命周期接口
  • 在activity的onNewIntent接口中进行调用

接口声明

public static void onNewIntent(Activity activity, Intent intent) 
1

调用示例

     @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        MarketSDK.onNewIntent(this, intent);
    }
1
2
3
4
5

# 3.7 获取appsflyer设备唯一标识

场景介绍

  • 为避免同一个用户自己生成邀请链接,自己点击进游戏获取奖励,可能您需要这个接口
  • 注意:经过测试此接口获取到的值,如果玩家卸载重装,这个值可能会变化

接口声明

public static String getAppsflyerUID(Activity activity) 
1

调用示例

    String id = MarketSDK.getAppsflyerUID(this);
1
本文档对解决你的问题有所帮助?