Unity/서버

0708_ 서버 (firebase_구글 아날리틱스)

minquu 2021. 7. 8. 11:27
반응형

저번 시간에 파이어베이스 로그인 까지 실시하였다.

 

이번에는 구글 아날리틱스를 붙여본다.

 

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

 

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

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

firebase.google.com

 

도큐먼터리 참고하면서 하기

 

 

유니티와 구글 아날리틱스 두 개가 있다.

 

둘 다 기능은 비슷하다.

 

이벤트를 정의를 잘해야하고, 어디에 이벤트를 트리거 달 건지, 매개 변수를 멀 넘길건지 

 

잘 짜여야한다. (규칙을 잘 정해야한다.)

 

어떤 스테이지가 끝나면 끝났다는 이벤트를 심어야한다.

 

 

 

 

파이어 베이스 콘솔을 먼저 연다.

 

대쉬보드를 들어간다.

 

이벤트 는 기본으로 4개가 달려잇음 

전환으로 해야지 사용이 된다.

(전환을 해야지 집계까 된다.)

 

 

 

 

 

이벤트를 만들 수 있다 . (쌤은 이거 안 만들고 넘김)

 

 

----

 

파라미터 상수목록

 

https://firebase.google.com/docs/reference/unity/class/firebase/analytics/firebase-analytics?hl=ko#eventaddpaymentinfo

 

Firebase.Analytics.FirebaseAnalytics Class Reference

firebase.ml.naturallanguage.translate

firebase.google.com

 

 

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

 

사용자 속성 설정  |  Firebase

사용자 속성은 언어 환경설정, 지리적 위치와 같이 사용자층을 나눈 세그먼트를 기술하고자 개발자가 정의하는 속성입니다. 애널리틱스는 몇 가지 사용자 속성을 자동으로 로깅하며, 이러한 속

firebase.google.com

 

 

우리가 이걸 이용해서 원하는걸 얻을 수 있다 .

 

 

https://support.google.com/firebase/answer/10075209?hl=ko&;ref_topic=6317489&visit_id=637613052454341583-1966623457&rd=1#create-property 

 

[GA4] 맞춤 측정기준 및 측정항목 - Firebase 고객센터

도움이 되었나요? 어떻게 하면 개선할 수 있을까요? 예아니요

support.google.com

맞춤 측정 기준 만들기

 

 

이코드에서 favorite_food 가 맞춤 등록이 안되어있으면 작동을 하지 않는다.

 

 

 

 

이벤트 매개변수는 기본적으로 있는 것도있고, 우리가 직접 만들수도있다.

 

근데! 

 

유니티에서 바로 코드를 쳐도 이벤트가 들어갈수도있다. 

 

만든건 보관처리를 해준다.

 

----

 

유니티로

 

튜토리얼 버튼 하나 뚫어서 눌렀을 때 이벤트가 나오게하기

 

 

먼저 아날리틱스 패키지를 유니티에 임포트해준다.

 

우리가 테스트 할 건, 게임에 처음 접속하면 튜토리얼이 실행되고

 

튜토리얼을 증가시키면 최대 5 까지, 한 인원수 를 알 수 있도록 할 것잇다.

 

https://youtu.be/JDxXiarsrHk

 

튜토리얼 

 

 

넥스트 누르면 튜토리얼 증가, 그리고 닫으면 현재 튜토리얼 숫자가 넘어간다.

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIPopTutorail : 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;
            }
        });

        this.btnClose.onClick.AddListener(() =>
        {
            Close();
        });
    }
    public void Open()
    {
        this.gameObject.SetActive(true);
    }

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

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

App.cs 에서는 

받아서 

로그인 되고나서 열리도록 해야한다.

 

 

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

public class App : MonoBehaviour
{
    public enum ePlayMode { 
        TEST, BUILD
    }
    public Text txtAuthenicate;
    public Text test;
    public Text txtid;
    public Text txtUserName;
    public Text txtState;
    public Image thumb;
    public ePlayMode playMode;
    public UIPopTutorail popTutorial;

    // Start is called before the first frame update
    void Start()
    {


        Debug.Log("-----------------> lnit GPGS");

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
            .RequestIdToken()
            .EnableSavedGames()
            .Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
        Debug.Log("----------------->Authenticate");

        // authenticate user:
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (result) => {
            // handle results

            this.txtAuthenicate.text = result.ToString();


            if (result == SignInStatus.Success)
            {
                var localUer = (PlayGamesLocalUser)Social.localUser;
                var googleIdToken = localUer.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);
                });
            }

            Debug.Log("----------------->" + result);
            Debug.Log("----------------->" + Social.localUser);
            Debug.Log("----------------->" + Social.localUser.authenticated);

            if (Social.localUser.authenticated) {


                this.txtid.text = Social.localUser.id;
                this.txtUserName.text = Social.localUser.userName;
                this.txtState.text = Social.localUser.state.ToString();

                Debug.Log("----------------->" + Social.localUser.image);

                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();
                }));


                this.popTutorial.Init();
                this.popTutorial.Open();

            }

        });


    }
    private IEnumerator WaitForLoadThumb(System.Action callback) {
        while (true) {
            if (Social.localUser.image != null) {
                break;
            }
            yield return null;
        }
        callback();
    }
}

 

----

 

이러면 내가 이벤트를 심어 놓은것이다.

 

24시간 뒤에 대쉬보드에 쌓인다.

 

 

추가적으로

 

패키지매니저 - 안드로이드 로그캣 인스톨 - 윈도우 - 아날리틱스 - 안드로이드 고르캣

 

노 디바이스 클릭

 

ip 127.0.0.1 

port 62001

 

입력하면 녹스실행해서 유니티에서 로그를 찍을 수 있다. 

 

cmd adb 안 해도 된다.

 

근데 이건 디바이스 로그를 못봐서 그렇게 추천은 안함 ! 

 

 

 

----

 

바로 볼수있는 방법을 찾아보자

 

adb.exe  에서 

 

adb shell setprop debug.firebase.analytics.app <패키지이름>
adb shell setprop debug.firebase.analytics.app com.oceancleaner.oceancleaner

 

이 명령어를 쳐주면

 

몇분 뒤

 

기기가 잡힌다.

 

내가 녹스에서 

 

 

 

3를 하고 튜토리얼을 닫으면 ->

 

 

 

 

 

내가 심은 페이지 에 3이라는 변수값이 들어온걸 실시간으로 확인할수있다. 

반응형