0708 구글 애널리틱스

2021. 7. 8. 11:55Node.js

https://firebase.google.com/docs/analytics/unity/start?hl=ko 

 

Unity에서 Google 애널리틱스 시작하기  |  Firebase

Google 애널리틱스는 앱의 사용량과 행동 데이터를 수집합니다. 이 SDK는 다음 두 가지 기본 유형의 정보를 로깅합니다. 이벤트: 사용자 행동, 시스템 이벤트, 오류 등 앱에서 발생하는 상황입니다.

firebase.google.com

애널리틱스는 몇 가지 이벤트와 사용자 속성을 자동으로 로깅하며 별도의 코드 없이 이러한 속성을 사용 설정할 수 있습니다.

유니티에 임포트 해야함

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;

public class App : MonoBehaviour
{
    public Text txtVersion;
    public Text txtId;
    public Text txtUsername;
    public Text txtState;
    public Image thumb;
    public Text txtAuthenticate;
    public UIPopupTutorial popup;

    // Start is called before the first frame update
    void Start()
    {
        this.txtVersion.text = Application.version;
        

        Debug.Log("================================= init GPGS =================================");

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()

            .EnableSavedGames()
            .RequestIdToken()
            .Build();

        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();

        Debug.Log("================================= authenticate =================================");

        // authenticate user:
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (result) => {
            Debug.Log("================================= result =================================" + result);
            Debug.Log("================================= local User =================================" + Social.localUser);
            Debug.Log("================================= autenciated =================================" + Social.localUser.authenticated);

            this.txtId.text = Social.localUser.id;
            this.txtUsername.text = Social.localUser.userName;
            this.txtState.text = Social.localUser.state.ToString();
            this.txtAuthenticate.text = result.ToString();

            if (result == SignInStatus.Success)
            {
                var localUser = (PlayGamesLocalUser)Social.localUser;
                var googleIdToken = localUser.GetIdToken();
                Debug.LogFormat("googleIdToken: {0}", googleIdToken);

                Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
                Firebase.Auth.Credential credential =
                Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, null);
                auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                    if (task.IsCanceled)
                    {
                        Debug.LogError("SignInWithCredentialAsync was canceled.");
                        return;
                    }
                    if (task.IsFaulted)
                    {
                        Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                        return;
                    }

                    Firebase.Auth.FirebaseUser newUser = task.Result;
                    Debug.LogFormat("User signed in successfully: {0} ({1})",
                        newUser.DisplayName, newUser.UserId);

                    this.popup.Init();
                    this.popup.Open();

                });
            }

            StartCoroutine(this.WaitforLoadThumb(() =>
            {
                Debug.Log(Social.localUser.image);
                Debug.LogFormat("{0}{1}", Social.localUser.image.width, Social.localUser.image.height);
                this.thumb.sprite = Sprite.Create(Social.localUser.image, new Rect(0, 0, Social.localUser.image.width, Social.localUser.image.height), Vector2.zero);
                this.thumb.SetNativeSize();
            }));
        });
    }
    private IEnumerator WaitforLoadThumb(System.Action callback)
    {
        while (true)
        {
            if (Social.localUser.image != null)
            {
                break;
            }
            yield return null;
        }
        callback();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIPopupTutorial : MonoBehaviour
{
    public Button btnClose;
    public Button btnNext;
    public Text txtPageNum;
    private int currentPage=1;
    private int totalPage = 5;


    public void Init() 
    {
        this.btnNext.onClick.AddListener(() =>
        {
            if (this.currentPage >= this.totalPage) 
            {
                this.currentPage++;
                var str = string.Format("{0}/{1}", this.currentPage, this.totalPage);
                Debug.Log(str);
                this.txtPageNum.text = str;
                Firebase.Analytics.FirebaseAnalytics.LogEvent("tutorial","page",this.currentPage);
            }
        });
        this.btnClose.onClick.AddListener(() =>
        {
            this.Close();
        });
        
    }

    public void Open() 
    {
        this.gameObject.SetActive(true);
        
    }

    public void Close() 
    {
        this.gameObject.SetActive(false);
        Firebase.Analytics.FirebaseAnalytics.LogEvent("end_toturials","page",currentPage);

    }
}

 

'Node.js' 카테고리의 다른 글

express 서버 열어서 POST/GET  (0) 2021.07.12
유니티 연동 카카오 로그인  (0) 2021.07.08
0630 firebase + google analytics  (0) 2021.06.30
Naver login  (0) 2021.06.24
GPGS Achievement  (0) 2021.06.23