Android Studio 接入 GameAdjust SDK

GameAnalytics | Trusted by 100K Game Developershttps://gameanalytics.com/

快速入门

添加LIB

请添加以下LIB文件到您的项目:

百度云

链接:https://pan.baidu.com/s/1KhSo1uJcw6XSaXsTAsgqmg 
提取码:abcd 

Android Studio 接入 GameAdjust SDK_第1张图片

添加依赖项

请添加下行到您的 build.gradle 文件:

implementation(name: 'gameanalytics', ext:'aar')

添加权限

请添加下行到您的 AndroidManifest.xml 文件:


初始化GA

请添加下行到您的 Activity 类里 这里以 Unity为案例

导入库

import com.adjust.sdk.AdjustEvent;
import com.gameanalytics.sdk.GameAnalytics;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

GA初始化代码

在 onCreate 方法内调用

//GA Log Tag
public  static final String GA_TAG = "GA";
//GA Init
public void GAInit()
{
    String gameKey = "{ You Gamekey }";    // String gameKey = "aaaaaaaaaaa";
    String gameSecret = "{ You Secret }";  // String gameSecret = "abcdefg12313213";

    PackageManager pm = getPackageManager();
    PackageInfo info = null;
    try {
        info = pm.getPackageInfo(getPackageName(), 0);
        GameAnalytics.configureBuild(info.versionName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    GameAnalytics.initializeWithGameKey(this, gameKey, gameSecret);
}

GA事件代码

注意:  GAEvent是由 冒号 组成的字符串       

例如:  LoginEvent:Time:2021/11/15

//如上  LoginEvent 类型   Key是 Time  值 是 2021/11/15     全意在向GA后台反馈玩家登陆事件 并 描述时间字段

  //GA Event Dispatch
    public void GAEvent(String event)
    {
        try {
             Log.d(GA_TAG,event);
             GameAnalytics.addDesignEventWithEventId(event);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

GAEvent方法 封装 - 以C#案例

    public void SendEvent(string type, string key, string value )
    {

#if !UNITY_EDITOR

        
        var javaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var javaObject = javaClass.GetStatic("currentActivity");

        string evt = $"{type}:{key}:{value}";
        javaObject.Call("GAEvent", evt);


#endif
    }

你可能感兴趣的:(Android,android,java,GameAdjust,Unity,android,studio)