Athana SDK

For Games

归因服务

支持的三方平台

平台 依赖适配
AppsFlyer com.inonesdk.athana:conversion-appsflyer
Firebase com.inonesdk.athana:conversion-firebase
Meta com.inonesdk.athana:conversion-meta

配置

AppsFlyer

  • 如果需要支持 W2A 的投放方式,或者延迟深链,则需要配置 OneLink 以及自定义 Schema

编辑 AndroidManifest.xml,在入口 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
33
34
35
36
37
38
39
40
<!-- launcher/src/main/AndroidManifest.xml -->
<manifest ..>
<application ..>
...
<!-- 添加在入口Activity中 -->
<activity ..>

<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<!-- 增加以下内容 Start -->
<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" />
<!-- 请联系对接的产品经理获取 OneLink 的定义 -->
<data android:host="***.onelink.me" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- 请定义一个 URL Scheme,并提供给对接的产品经理 -->
<data android:scheme="****" />
<data android:host="app" />
</intent-filter>
<!-- 增加以上内容 End -->

</activity>
</application ..>
</manifest>
  • 初始化
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// DemoApplication.kt
class DemoApplication: Application() {
override fun onCreate() {
super.onCreate()

...

// -- AppsFlyer 配置
val afDevKey = "<AppsFlyer Dev Key>" // 联系对接的产品经理获取
// 【方式 1 】不需要针对安装参数做额外逻辑处理的配置方式
AppsFlyerSdkConfiguration.initialize(sdkKey = afDevKey)

// 【方式 2 】需要针对安装参数做额外逻辑处理(跳转到指定页面等)的配置方式
AppsFlyerSdkConfiguration.initialize(sdkKey = afDevKey,
{ dpResult -> // DeepLinking 回调监听
when (dpResult.status) {
DeepLinkResult.Status.FOUND -> {
// 保存结果至内存中,便于后续流程(页面跳转)使用
save(
HashMap<String, Any>().apply {
val dl = dpResult.deepLink
put("af_sub1", dl.afSub1 ?: "")
put("af_sub2", dl.afSub2 ?: "")
put("af_sub3", dl.afSub3 ?: "")
put("af_sub4", dl.afSub4 ?: "")
put("af_sub5", dl.afSub5 ?: "")
put("timestamp", dl.getStringValue("timestamp") ?: "")
put("match_type", dl.getStringValue("match_type") ?: "")
put("deep_link_value", dl.deepLinkValue ?: "")
put("is_deferred", dl.getStringValue("is_deferred") ?: "")
}
)
}
DeepLinkResult.Status.NOT_FOUND -> {
// 未识别对应的数据
}
DeepLinkResult.Status.ERROR -> {
// 识别过程出现异常
// 大部分由 AppsFlyer 初始化失败引起
}
}
},
// 归因结果监听
object : AppsFlyerConversionListener {
override fun onConversionDataSuccess(p0: MutableMap<String, Any>?) {
// 归因结果回调
Log.i(LogTag.TAG, "[AF] onConversionDataSuccess: $p0")
val firstLaunch : Boolean = p0?.get("is_first_launch") as Boolean? ?: true
if (firstLaunch) {
// 安装后第一次启动

}
if (p0 != null) {
// 保存结果至内存中,便于后续流程(页面跳转)使用
save(p0)
}
}

override fun onConversionDataFail(p0: String?) {
// 归因失败
}

override fun onAppOpenAttribution(p0: MutableMap<String, String>?) {
// 获取应用打开的归因参数
}

override fun onAttributionFailure(p0: String?) {
Log.w(LogTag.TAG, "[AF] onAttributionFailure: $p0")
}

})

// Athana SDK Config
// ...
// Athana.initialize(...)
}
}
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// DemoApplication.java
public class DemoApplication extends Application {

@Override
public void onCreate() {
super.onCreate();

...

// -- AppsFlyer 配置
String afDevKey = "<AppsFlyer Dev Key>"; // 联系对接的产品经理获取
// 【方式 1 】不需要针对安装参数做额外逻辑处理的配置方式
AppsFlyerSdkConfiguration.initialize(afDevKey, null, null);

// 【方式 2 】需要针对安装参数做额外逻辑处理(跳转到指定页面等)的配置方式
AppsFlyerSdkConfiguration.initialize(afDevKey,
new DeepLinkListener() {

@Override
public void onDeepLinking(@NonNull DeepLinkResult dpResult) {
switch (dpResult.getStatus()) {
case FOUND: {
// 保存结果至内存中,便于后续流程(页面跳转)使用
Map<String, Object> cacheMap = new HashMap<>();
DeepLink dl = dpResult.getDeepLink();
if (dl != null) {
cacheMap.put("af_sub1", dl.getAfSub1());
cacheMap.put("af_sub2", dl.getAfSub2());
cacheMap.put("af_sub3", dl.getAfSub3());
cacheMap.put("af_sub4", dl.getAfSub4());
cacheMap.put("af_sub5", dl.getAfSub5());
cacheMap.put("timestamp", dl.getStringValue("timestamp"));
cacheMap.put("match_type", dl.getStringValue("match_type"));
cacheMap.put("deep_link_value", dl.getDeepLinkValue());
cacheMap.put("is_deferred", dl.getStringValue("is_deferred"));
}
}
case NOT_FOUND: {
// 未识别对应的数据
}
case ERROR: {
// 识别过程出现异常
// 大部分由 AppsFlyer 初始化失败引起
}
}
}
},
// 归因结果监听
new AppsFlyerConversionListener() {
@Override
public void onConversionDataSuccess(Map<String, Object> map) {
// 归因结果回调
Log.i(LogTag.TAG, "[AF] onConversionDataSuccess: " + map);
if (map != null) {
Object firstLaunch = map.get("is_first_launch");
if (firstLaunch instanceof Boolean) {
if ((Boolean) firstLaunch) {
// 安装后第一次启动
}
}

// 保存结果至内存中,便于后续流程(页面跳转)使用
save(map);
}
}

@Override
public void onConversionDataFail(String s) {
// 归因失败
}

@Override
public void onAppOpenAttribution(Map<String, String> map) {
// 获取应用打开的归因参数
}

@Override
public void onAttributionFailure(String s) {
Log.w(LogTag.TAG, "[AF] onAttributionFailure: " + s);
}
});

// Athana SDK Config
// ...
//Athana.initialize(...);
}

}

参考文档:

AppsFlyer SDK 官方对接指南

Firebase

将得到的 google-services.json 文件添加到 applauncher 目录中

Meta

确定 app/build.gradlelauncher/build.gradle 中的 FB_APP_IDFB_CLIENT_TOKEN 填写正确

0%