반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2024/03   »
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
Archives
Today
Total
관리 메뉴

가끔 보자, 하늘.

Google Analytics 연동하기 - 2. API 살펴보기 본문

개발 이야기/개발 및 서비스

Google Analytics 연동하기 - 2. API 살펴보기

가온아 2015. 7. 7. 10:31

(* 원문 : https://developers.google.com/analytics/devguides/collection/unity/v3/reference?hl=ko )

*역자주 : 원문을 그대로 변역하는게 아닌, 실무에 적용하면서 불필요하게 긴 내용은 빼고, 추가할 내용은 넣으면서 진행합니다. 번역이 아님을 알아주세요. ^^a


데이터를 보낼 때는 Basic 나 Builder method를 사용합니다. Builder method들은 보낼 정보들에 대한 수치, campaign 파라미터들을 추가하길 원할 때 사용됩니다. 


Dispatch Hits

네트웍 연결이 가능하다면 데이터를 전송한다.

public void DispatchHits();


Session Control

Session들은 스크린 뷰, 이벤트들 그리고 전사상거래 업무 등과 과 같은 의미있는 행동들을 포함한 유요한 커네이너들을 제공한다.


아래 메소드들은 강제로 세션을 시작하거나 종료할 수 있다.

// Start a new session.
public void StartSession();
// There should be no need to end a session explicitly. However, if you do
// need to indicate the end of session you can use the following method.
public void StopSession();

Screens


GA에서 Screens는 게임안에서 보이는 유저 컨텐츠를 대표한다. screen은 단일 문자열 필드로 구성되어 있으며, GA 리포트에서 screen name으로 구분되어진다.


basic 

public void LogScreen(string title);

Builder

public void LogScreen(AppViewHitBuilder builder);

Example

googleAnalytics.LogScreen("Main Menu");

//Builder Hit with all App View parameters (all parameters required):
googleAnalytics
.LogScreen(new AppViewHitBuilder()
   
.SetScreenName("Main Menu"));


Events

Events는 유저의 반응에 대한 데이터를 모으는데 유용한 방법이다. 네 개의 파라미터를 사용하며, 게임의 유저 반응을 묘사하는데 사용할 수 있다. 


Basic

public void LogEvent(string eventCategory,
   
string eventAction,
   
string eventLabel,
   
long value);

Builder

public void LogEvent(EventHitBuilder builder);

Example

googleAnalytics.LogEvent("Achievement", "Unlocked", "Slay 10 dragons", 5);

// Builder Hit with all Event parameters.
googleAnalytics
.LogEvent(new EventHitBuilder()
   
.SetEventCategory("Achievement")
   
.SetEventAction("Unlocked")
   
.SetEventLabel("Slay 10 dragons")
   
.SetEventValue(5));

// Builder Hit with minimum required Event parameters.
googleAnalytics
.LogEvent(new EventHitBuilder()
   
.SetEventCategory("Achievement")
   
.SetEventAction("Unlocked"));


Crashes & Exceptions

충돌과 예외에 대해 측정할 수 있다.


Basic

public void LogException(string exceptionDescription, bool isFatal);

Builder

public void LogException(ExceptionHitBuilder builder);

Example

googleAnalytics.LogException("Incorrect input exception", true);

// Builder Hit with all Exception parameters.
googleAnalytics
.LogException(new ExceptionHitBuilder()
   
.SetExceptionDescription("Incorrect input exception")
   
.SetFatal(true));

// Builder Hit with minimum required Exception parameters.
googleAnalytics
.LogException(new ExceptionHitBuilder());


User Timings

GA에서 시간의 간격을 측정하는 기본적인 방법을 제공한다. 예를들면, 리소스 로딩 시간을 측정하는데 유용할 수 있다.


Basic

public void LogTiming(string timingCategory,
   
long timingInterval,
   
string timingName,
   
string timingLabel);

Builder

public void LogTiming(TimingHitBuilder builder);

Example

googleAnalytics.LogTiming("Loading", 50L, "Main Menu", "First Load");

// Builder Hit with all Timing parameters.
googleAnalytics
.LogTiming(new TimingHitBuilder()
   
.SetTimingCategory("Loading")
   
.SetTimingInterval(50L)
   
.SetTimingName("Main Menu")
   
.SetTimingLabel("First load"));

// Builder Hit with minimum required Timing parameters.
googleAnalytics
.LogTiming(new TimingHitBuilder()
   
.SetTimingCategory("Loading"));

Social Interactions

컨텐츠 안에 내장된 여러 SNS, 추천 위젯 등에 대한 유저 반응을 측정할 수 있다.


Basic

public void LogSocial(string socialNetwork,
   
string socialAction,
   
string socialTarget);

Builder

public void LogSocial(SocialHitBuilder builder);

Example

googleAnalytics.LogSocial("twitter", "retweet", "twitter.com/googleanalytics/status/482210840234295296");

// Builder Hit with all Social parameters (all parameters required).
googleAnalytics
.LogSocial(new SocialHitBuilder()
   
.SetSocialNetwork("Twitter")
   
.SetSocialAction("Retweet")
   
.SetSocialTarget("twitter.com/googleanalytics/status/482210840234295296"));


E-Commerce

GA에 in-game 구매와 판매에 대한 정보를 전달한다.


* 참고 : 이 절차는 GA에서 "전자상거래 보고서"를 사용하기 위해 설정이 필요합니다. (https://support.google.com/analytics/answer/1009612?hl=ko#Enable)


Basic

public void LogTransaction(string transID,
   
string affiliation,
   
double revenue,
   
double tax,
   
double shipping);

public void LogTransaction(string transID,
   
string affiliation,
   
double revenue,
   
double tax,
   
double shipping,
   
string currencyCode);

Builder

public void LogTransaction(TransactionHitBuilder builder);

Example

googleAnalytics.LogTransaction("TRANS001", "Coin Store", 3.0, 0.0, 0.0);
googleAnalytics
.LogTransaction("TRANS001", "Coin Store", 3.0, 0.0, 0.0, "USD");

// Builder Hit with all Transaction parameters.
googleAnalytics
.LogTransaction(new TransactionHitBuilder()
   
.SetTransactionID("TRANS001")
   
.SetAffiliation("Coin Store")
   
.SetRevenue(3.0)
   
.SetTax(0)
   
.SetShipping(0.0)
   
.SetCurrencyCode("USD"));

// Builder Hit with minimum required Transaction parameters.
googleAnalytics
.LogTransaction(new TransactionHitBuilder()
   
.SetTransactionID("TRANS001")
   
.SetAffiliation("Coin Store"));


Items

Basic

public void LogItem(string transID,
   
string name,
   
string SKU,
   
string category,
   
double price,
   
long quantity);

public void LogItem(string transID,
   
string name,
   
string SKU,
   
string category,
   
double price,
   
long quantity,
   
string currencyCode);

Builder

public void LogItem(ItemHitBuilder builder);

Example

googleAnalytics.LogItem("TRANS001", "Sword", "SWORD1223", "Weapon", 3.0, 2);
googleAnalytics
.LogItem("TRANS001", "Sword", "SWORD1223", "Weapon", 3.0, 2, "USD");

// Builder Hit with all Item parameters.
googleAnalytics
.LogItem(new ItemHitBuilder()
   
.SetTransactionID("TRANS001")
   
.SetName("Sword")
   
.SetSKU("SWORD1223")
   
.SetCategory("Weapon")
   
.SetPrice(3.0)
   
.SetQuantity(2)
   
.SetCurrencyCode("USD"));

// Builder Hit with minimum required Item parameters.
googleAnalytics
.LogItem(new ItemHitBuilder()
   
.SetTransactionID("TRANS001")
   
.SetName("Sword")
   
.SetSKU("SWORD1223"));

Custom Dimensions & Metrics

Custom Dimemsions은 GA에서 hits, 유저들, 그리고 세션들을 가진 metadata의 묶음이다. Custom Metrics는 GA에서 당신 자신의 통계를 생성하고 증가시킬 수 있다.


사용전에 각각에 대해 생성과 설정이 필요하다. 설정 이후에는 Builder method를 통해 해당 부분으로 전송될 수 있다.


Builder

// Custom Dimension.
public T SetCustomDimension(int dimensionNumber, string value);
// Custom Metric.
public T SetCustomMetric(int metricNumber, string value);


Example

// Custom Dimension.
// An AppView hit example, but custom dimensions can be sent with all hit types.
googleAnalytics
.LogScreen(new AppViewHitBuilder()
   
.SetScreenName("Another screen")
   
.SetCustomDimension(1, "200"));

// Custom Metric.
// An Event hit example, but custom metrics can be sent with all hit types.
googleAnalytics
.LogEvent(new EventHitBuilder()
   
.SetEventCategory("Achievement")
   
.SetEventAction("Unlocked")
   
.SetEventLabel("Slay 10 dragons")
   
.SetEventValue(5)
   
.SetCustomMetric(3, "200"));

Campaigns

GA에서 Campaigns는 게임에서 유저가 활성화하는 campaigns와 통신 소스들의 속성을 활성화한다.

Campaign 파라미터들은 Builder method를 사용해 어떤 hit의 부분으로 보내질 수 있다.


Build

public T SetCampaignName(string campaignName);
public T SetCampaignSource(string campaignSource);
public T SetCampaignMedium(string campaignMedium);
public T SetCampaignKeyword(string campaignKeyword);
public T SetCampaignContent(string campaignContent);
public T SetCampaignID(string campaignID);

Example

googleAnalytics.LogTiming(new TimingHitBuilder()
   
.SetTimingCategory("Loading")
   
.SetTimingInterval(50L)
   
.SetTimingName("Main Menu")
   
.SetTimingLabel("First load")
   
.SetCampaignName("Summer Campaign")
   
.SetCampaignSource("google")
   
.SetCampaignMedium("cpc")
   
.SetCampaignKeyword("games")
   
.SetCampaignContent("Free power ups")
   
.SetCampaignId("Summer1"));

// Send campaign parameters with timing hit.
// Builder Hit with minimum required Campaign parameters.
googleAnalytics
.LogTiming(new TimingHitBuilder()
   
.SetTimingCategory("Loading")
   
.SetTimingInterval(50L)
   
.SetTimingName("Main Menu")
   
.SetTimingLabel("First load")
   
.SetCampaignSource("google");


Advanced

이 method는 오직 tracker concepts를 가진, GA의 파워유저가 사용하길 추천한다. 


SetOnTracker

다른 hits로 보내진 값을 추적하는 값을 세팅하는 것. (? 약간 이해가 안감. 테스트하면서 다시 봐야 할 듯.)

fieldName 파라미터를 위해 Assets/Plugins/Fields.cs 의 변수들을 사용해라. (예를들면,Fields.SCREEN_NAME 같은..)

public void SetOnTracker(Field fieldName, object value);

* 참고: 같은 값을 전달하면 중복됩니다.


Example

googleAnalytics.SetOnTracker(Fields.SCREEN_NAME, "Main Menu");


Dispose

관리중인 리소스들을 해제하고 tracker를 초기화 한다.


만약 dispose 이후에 어떤 tracking hit이 호출되면, 새로운 tracker가 생성된다. dispose는 실제로 모든 tracking이 완료된 이후에 호출할 것! 예를들면, 게임이 종료될 때.

public void Dispose();

Example

googleAnalytics.Dispose();


이상. 일단 기본 API 문서를 살펴보았다.


다음에는 Unity 테스트 프로젝트에 적용하고, 그 결과를 Google Analytics 보고서에서 보는 결과를 정리하겠다.


즐건 하루 ! 



반응형