이 문서에서는 데이터를 전송하는 방법을 설명하고 Unity용 Google 애널리틱스 플러그인의 모든 메서드를 나열합니다.
소개
Unity용 GA 플러그인을 사용하여 Google 애널리틱스로 데이터를 전송할 때 기본 메서드 또는 Builder 메서드를 사용할 수 있습니다. 조회에 캠페인 매개변수, 맞춤 측정기준 또는 측정항목을 추가하려면 Builder 메서드가 필요합니다. 두 방법 중 하나를 사용하여 조회를 전송할 수 있습니다.
개발자 가이드에 따라 프로젝트에 Unity용 Google 애널리틱스 플러그인을 설정하고 구성하세요.
일반
디스패치 히트곡
네트워크 연결을 사용할 수 있는 경우 조회 (이벤트, 조회 등)를 Google 애널리틱스로 전달합니다.
public void DispatchHits();
관련 리소스:
세션 제어
세션은 사용자와 게임의 단일 상호작용을 나타냅니다. 세션은 화면 조회수, 이벤트, 전자상거래 데이터를 포함하여 측정된 활동의 유용한 컨테이너 역할을 합니다.
다음 방법을 사용하여 세션 시작 또는 종료를 강제로 실행할 수 있습니다.
// 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();
관련 리소스:
화면
Google 애널리틱스의 화면은 사용자가 게임 내에서 보고 있는 콘텐츠를 나타냅니다. 화면 조회수는 Google 애널리틱스 보고서에서 화면 이름으로 사용되는 단일 문자열 필드로 구성됩니다.
기본
public void LogScreen(string title);
Builder
public void LogScreen(AppViewHitBuilder builder);
예
googleAnalytics.LogScreen("Main Menu"); //Builder Hit with all App View parameters (all parameters required): googleAnalytics.LogScreen(new AppViewHitBuilder() .SetScreenName("Main Menu"));
관련 리소스:
이벤트
이벤트는 사용자의 상호작용(예: 특정 항목 사용)에 대한 데이터를 수집하는 데 유용한 방법입니다. 이벤트는 사용자의 게임 상호작용을 설명하는 데 사용할 수 있는 4개의 필드로 구성됩니다.
기본
public void LogEvent(string eventCategory, string eventAction, string eventLabel, long value);
Builder
public void LogEvent(EventHitBuilder builder);
예
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"));
관련 리소스:
오류 및 예외
비정상 종료 및 예외 측정을 사용하면 게임에서 발생한 비정상 종료 및 포착되지 않은 비정상 종료와 예외의 수와 유형을 측정할 수 있습니다.
기본
public void LogException(string exceptionDescription, bool isFatal);
Builder
public void LogException(ExceptionHitBuilder builder);
예
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());
관련 리소스:
사용자 시간
사용자 시간을 측정하면 Google 애널리틱스에서 기본 기간을 측정할 수 있습니다. 예를 들어 이 방식은 리소스 로드 시간을 측정하는 데 유용할 수 있습니다.
기본
public void LogTiming(string timingCategory, long timingInterval, string timingName, string timingLabel);
Builder
public void LogTiming(TimingHitBuilder builder);
예
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") .SetTimingInterval(50L));
관련 리소스:
소셜 상호작용
소셜 상호작용 측정을 사용하면 콘텐츠에 삽입된 다양한 소셜 네트워크 공유 및 추천 위젯과의 사용자 상호작용을 측정할 수 있습니다.
기본
public void LogSocial(string socialNetwork, string socialAction, string socialTarget);
Builder
public void LogSocial(SocialHitBuilder builder);
예
googleAnalytics.LogSocial("twitter", "retweet", "twitter.com/googleanalytics/status/482210840234295296"); // Builder Hit with all Social parameters. googleAnalytics.LogSocial(new SocialHitBuilder() .SetSocialNetwork("Twitter") .SetSocialAction("Retweet") .SetSocialTarget("twitter.com/googleanalytics/status/482210840234295296")); // Builder Hit with minimum required Social parameters. googleAnalytics.LogSocial(new SocialHitBuilder() .SetSocialNetwork("Twitter") .SetSocialAction("Retweet"));
관련 리소스:
전자상거래
전자상거래 측정을 사용하면 인게임 구매 및 판매를 Google 애널리틱스로 전송할 수 있습니다. Google 애널리틱스의 전자상거래 데이터는 공유된 거래 ID와 연결된 거래 및 상품 조회로 구성됩니다.
트랜잭션
기본
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);
예
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") .SetRevenue(3.0) .SetTax(0) .SetShipping(0.0));
항목
기본
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);
예
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") .SetPrice(3.0) .SetQuantity(2));
관련 리소스:
맞춤 측정기준 및 측정항목
맞춤 측정기준을 사용하면 메타데이터를 Google 애널리틱스에서 조회수, 사용자 수, 세션과 연결할 수 있으며, 맞춤 측정항목을 사용하면 Google 애널리틱스에서 자체 측정항목을 만들고 늘릴 수 있습니다.
사용하기 전에 맞춤 측정기준 및 맞춤 측정항목을 만들고 구성해야 합니다. 구성되면 Builder 메서드를 사용하여 조회의 일부로 데이터를 전송할 수 있습니다.
Builder
// Custom Dimension. public T SetCustomDimension(int dimensionNumber, string value);
// Custom Metric. public T SetCustomMetric(int metricNumber, string value);
예
// 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"));
관련 리소스:
캠페인
Google 애널리틱스에서 캠페인을 측정하면 캠페인 및 트래픽 소스를 게임 내 사용자 활동에 연결할 수 있습니다.
캠페인 매개변수는 Builder 메서드를 사용하여 조회의 일부로 전송할 수 있습니다.
Builder
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);
예
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");
관련 리소스:
고급
이러한 방법은 추적기 개념에 익숙한 Google 애널리틱스의 고급 사용자에게만 권장됩니다.
SetOnTracker
추적기에서 다른 조회와 함께 전송될 값을 설정합니다.
fieldName
매개변수에 Assets/Plugins/Fields.cs의 변수를 사용합니다 (예: Fields.SCREEN_NAME
).
public void SetOnTracker(Field fieldName, object value);
예
googleAnalytics.SetOnTracker(Fields.SCREEN_NAME, "Main Menu");
폐기
관리형 리소스를 확보하고 추적기를 재설정하세요.
폐기가 호출되면 다음 추적 조회는 새 추적기를 만들어야 하므로 추적이 완전히 완료된 경우에만 이 메서드를 호출하는 것이 좋습니다. 예를 들어 onDispose()
메서드를 사용하면 사용자가 게임을 종료할 때 실행됩니다.
public void Dispose();
예
googleAnalytics.Dispose();