モバイルアプリ実装ガイド

このドキュメントは、モバイル開発者の方を対象に、アナリティクスを使用してユーザーの操作を測定し、アプリの利用状況について把握する方法を説明しています。

はじめに

モバイルアプリ向け Google アナリティクスは、ユーザーの操作を測定するプラットフォームを提供し、お客様のアプリに対するユーザーの利用状況を詳細に把握して最適化する支援をします。

Google アナリティクスのデフォルトでは、アプリについて次の情報が自動的に提供されます。

  • ユーザーとセッションの数
  • セッション継続時間
  • オペレーティング システム
  • 携帯端末のモデル
  • 地域

このガイドでは、ユーザーとユーザーの行動をより深く理解するために Google アナリティクスの追加機能を実装する方法を説明します。

始める前に

このガイドでの作業を始める前に、以下の関連資料を読んで、モバイルアプリ向け Google アナリティクスの設定方法についてかくにんすることをおすすめします。

概要

ドラゴン キャッチャー

このガイドでは、サンプルアプリを使用して、追加の Google アナリティクス機能を実装する方法を見ていきます。このアプリは「ドラゴン キャッチャー(Dragon Catcher)」という名前の、次の特徴を持つゲームです。

  • 1 つのレベルは、プレーヤー、ドラゴン、フェンスで囲まれたエリア、泉、木から構成されます。
  • プレーヤーの目的は、ドラゴンをフェンスの内側に追い込んで捕まえることです。
  • プレーヤーは、レベル内の別のエリアや、泉や魔法の木が生えている場所などを訪れることができます。
  • プレーヤーは、すべてのドラゴンを捕まえると次のレベルに進みます。
  • プレーヤーは、第 1 レベルの「荒れ地(Barren Fields)」からゲームを開始します。

Google アナリティクスを使用すれば、ドラゴン キャッチャーでのユーザーの行動について、次のようなデータを取得することができます。

この後のセクションでは、ドラゴン キャッチャーに Google アナリティクス機能を実装することにより、上記についてのデータを取得する方法を解説します。

ユーザーがどんなアクションを実行しているか(イベント)

アプリ内でトラッキングしたい重要なアクションがあれば、このアクションを説明するために Google アナリティクスのイベントを使用することができます。イベントは、categoryactionlabelvalue の 4 つのパラメータで構成されます。Google アナリティクスにおけるイベントの仕組みについて詳しくは、イベント トラッキングのメカニズムをご覧ください。

たとえば、ユーザーがドラゴンを救出したり、レベル内の特定のエリアを訪れたりするアクションはドラゴン キャッチャーでは重要なため、イベントを使用して測定します。次のコード スニペットは、Google アナリティクスでこれらのアクションを測定する方法を示しています。

Android SDK v4

// To determine how many dragons are being rescued, send an event when the
// player rescues a dragon.
tracker.send(new HitBuilders.EventBuilder()
    .setCategory("Barren Fields")
    .setAction("Rescue")
    .setLabel("Dragon")
    .setValue(1)
    .build());

// To determine if players are visiting the magic tree, send an event when the
// player is in the vicinity of the magic tree.
tracker.send(new HitBuilders.EventBuilder()
    .setCategory("Barren Fields")
    .setAction("Visited")
    .setLabel("Magic Tree")
    .setValue(1)
    .build());

// To determine if players are visiting the well, send an event when the player
// is in the vicinity of the well.
tracker.send(new HitBuilders.EventBuilder()
    .setCategory("Barren Fields")
    .setAction("Visited")
    .setLabel("Well")
    .setValue(1)
    .build());

iOS SDK v3

// To determine how many dragons are being rescued, send an event when the
// player rescues a dragon.
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Barren Fields"
                                                      action:@"Rescue"
                                                       label:@"Dragon"
                                                       value:@1] build]];

// To determine if players are visiting the magic tree, send an event when the
// player is in the vicinity of the magic tree.
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Barren Fields"
                                                      action:@"Visited"
                                                       label:@"Magic Tree"
                                                       value:@1] build]];

// To determine if players are visiting the well, send an event when the player
// is in the vicinity of the well.
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Barren Fields"
                                                      action:@"Visited"
                                                       label:@"Well"
                                                       value:@1] build]];

Unity 用 Google アナリティクス プラグイン v3

// To determine how many dragons are being rescued, send an event when the
// player rescues a dragon.
googleAnalytics.LogEvent("Barren Fields", "Rescue", "Dragon", 1);

// To determine if players are visiting the magic tree, send an event when the
// player is in the vicinity of the magic tree.
googleAnalytics.LogEvent("Barren Fields", "Visited", "Magic Tree", 1);

// To determine if players are visiting the well, send an event when the player
// is in the vicinity of the well.
googleAnalytics.LogEvent("Barren Fields", "Visited", "Well", 1);

プレーヤーの「成績」を測定する

Google アナリティクスのイベントを使用して、プレーヤーの「成績」を測定することができます。たとえば、5 頭のドラゴンを救出するというアクションに対する成績を測定するには、プレーヤーが救出したドラゴンの数を記録し、プレーヤーがその基準値に達したら、イベントを Google アナリティクスに送信します。

Android SDK v4

if (numDragonsRescued > 5) {
  if (!user.hasAchievement(RESCUED_ACHIEVEMENT) {
    tracker.send(new HitBuilders.EventBuilder()
        .setCategory("Achievement")
        .setAction("Unlocked")
        .setLabel("5 Dragons Rescued")
        .setValue(1)
        .build());
  } else {
    tracker.send(new HitBuilders.EventBuilder()
        .setCategory("Achievement")
        .setAction("Earned")
        .setLabel("5 Dragons Rescued")
        .setValue(1)
        .build());
  }
}

iOS SDK v3

if (numDragonsRescued > 5) {
  if (![user hasAchievement:RESCUED_ACHIEVEMENT]) {
    [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Achievement"
                                                          action:@"Unlocked"
                                                           label:@"5 Dragons Rescued"
                                                           value:@1] build]];
  } else {
    [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Achievement"
                                                          action:@"Earned"
                                                           label:@"5 Dragons Rescued"
                                                           value:@1] build]];
  }
}

Unity 用 Google アナリティクス プラグイン v3

if (numDragonsRescued > 5) {
  if (!user.HasAchievement(RESCUED_ACHIEVEMENT) {
    googleAnalytics.LogEvent("Achievement", "Unlocked", "5 Dragons Rescued", 1);
  } else {
    googleAnalytics.LogEvent("Achievement", "Earned", "5 Dragons Rescued", 1);
  }
}

イベントに関するデベロッパー ガイド

イベントのレポート

イベントデータは以下でご確認いただけます。

ユーザーがアプリにどのくらいの金額を費やしているか(拡張 e コマース)

ユーザーによるアプリ内購入を測定したい場合は、e コマース トラッキングを使用して購入をトラッキングし、関連する商品の販売状況とユーザー行動を把握することができます。e コマース トラッキングは、特定の商品または仮想通貨の購入を測定する際に使用できます。

この例では、ドラゴン キャッチャーから、商品の購入を測定するために、 トランザクション データがイベントとともに Google アナリティクスに送信され ます。

Android SDK v4

Product product = new Product()
    .setName("Dragon Food")
    .setPrice(40.00);

ProductAction productAction = new ProductAction(ProductAction.ACTION_PURCHASE)
    .setTransactionId("T12345");

// Add the transaction data to the event.
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
    .setCategory("In-Game Store")
    .setAction("Purchase")
    .addProduct(product)
    .setProductAction(productAction);

// Send the transaction data with the event.
tracker.send(builder.build());

iOS SDK v3

GAIEcommerceProduct *product = [[GAIEcommerceProduct alloc] init];
[product setName:@"Dragon Food"];
[product setPrice:@40.00];

GAIEcommerceProductAction *productAction = [[GAIEcommerceProductAction alloc] init];
[productAction setAction:kGAIPAPurchase];
[productAction setTransactionId:@"T12345"];

GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createEventWithCategory:@"In-Game Store"
                                                                       action:@"Purchase"
                                                                        label:nil
                                                                        value:nil];
// Add the transaction data to the event.
[builder setProductAction:productAction];
[builder addProduct:product];

// Send the transaction data with the event.
[tracker send:[builder build]];

Unity 用 Google アナリティクス プラグイン v3

// Note: Using Android SDK v3 and standard Ecommerce tracking.

googleAnalytics.LogItem("T12345", "Dragon Food", "Food_SKU", "Items", 40.00, 1);
googleAnalytics.LogTransaction("T12345", "In-Game Store", 40.00, 0.00, 0.00);

ユーザーが仮想通貨を購入した場合、トランザクション データを Google アナリティクスに送信するときに現金換算で測定することをおすすめします。ユーザーが商品を購入するために仮想通貨を使用したら、イベントを使用してこれを測定します。例:

Android SDK v4

/**
 * When the user purchases the virtual currency (Gems) measure the transaction
 * using enhanced ecommerce.
 */
Product product =  new Product()
    .setName("2500 Gems")
    .setPrice(5.99);

ProductAction productAction = new ProductAction(ProductAction.ACTION_PURCHASE)
    .setTransactionId("T67890");

// Add the transaction to the screenview.
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

// Send the transaction with the screenview.
tracker.setScreenName("In-Game Store");
tracker.send(builder.build());


/**
 * When the user purchases an item using the virtual currency (Gems) send an
 * event to measure this in Google Analytics.
 */
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
    .setCategory("In-Game Store")
    .setAction("Purchase")
    .setLabel("Sword")
    .setValue(35);
tracker.send(builder.build());

iOS SDK v3

/**
 * When the user purchases the virtual currency (Gems) measure the transaction
 * using enhanced ecommerce.
 */
GAIEcommerceProduct *product = [[GAIEcommerceProduct alloc] init];
[product setName:@"2500 Gems"];
[product setPrice:@5.99];

GAIEcommerceProductAction *productAction = [[GAIEcommerceProductAction alloc] init];
[productAction setAction:kGAIPAPurchase];
[productAction setTransactionId:@"T67890"];

GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createScreenView];

// Add the transaction data to the screenview.
[builder setProductAction:productAction];
[builder addProduct:product];

// Send the transaction with the screenview.
[tracker set:kGAIScreenName value:@"In-Game Store"]
[tracker send:[builder build]];


/**
 * When the user purchases an item using the virtual currency (Gems) send an
 * event to measure this in Google Analytics.
 */
GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createEventWithCategory:@"In-Game Store"
                                                                       action:@"Purchase"
                                                                        label:@"Sword"
                                                                        value:@35];
[tracker send:[builder build]];

Unity 用 Google アナリティクス プラグイン v3

// Note: Using Android SDK v3 and standard Ecommerce tracking.

/**
 * When the user purchases the virtual currency (Gems) measure the transaction
 * using enhanced ecommerce.
 */

googleAnalytics.LogItem("T12345", "2500 Gems", "GEM2500_SKU", "Items", 5.99, 1);
googleAnalytics.LogTransaction("T12345", "In-Game Store", 5.99, 0.00, 0.00);

/**
 * When the user purchases an item using the virtual currency (Gems) send an
 * event to measure this in Google Analytics.
 */
googleAnalytics.LogEvent("In-Game Store", "Purchase", "Sword", 35);

拡張 e コマースのデベロッパー ガイド

拡張 e コマースのレポート

e コマース データは以下でご確認いただけます。

ユーザーによってアプリの目的は達成されたか(目標)

アプリ内でユーザーに達成してほしい目的があれば、 Google アナリティクスの目標を使用し、それらの 目的を定義して測定できます。たとえば、ユーザーが一定のゲームレベルに到達することやアイテムを購入することを目標に 設定できます。目標の仕組みについて、詳しくはヘルプセンターの目標についてを ご覧ください。

ドラゴン キャッチャー ゲームでは、購入のたびにイベントが Google アナリティクスに送信された場合に、アプリ内購入がいつ行われたかを測定するように目標を設定できます。管理画面の [アナリティクス設定] セクションで次のパラメータを使用すれば、 追加のコードを記述することなく目標を設定できます。

  • 目標タイプ(等しい): イベント
  • カテゴリ(等しい): ゲーム内ショップ
  • アクション(等しい): 購入
  • コンバージョンの目標値としてイベント値を使用: はい

目標レポート

目標のデータは以下でご確認いただけます。

特定の特性を持つユーザーの行動はどのようなものか? (カスタム ディメンションとカスタム指標)

特定の属性や特徴、メタデータを持つユーザーをトラッキングする場合は、カスタム ディメンションを使用してこのタイプのデータを Google アナリティクスに送信して分析します。カスタム ディメンションの仕組みについては、カスタム ディメンションとカスタム指標 - 機能のリファレンスをご覧ください。

たとえば、ドラゴン キャッチャーでは、第 1 レベルや第 2 レベルなどにいるユーザーの割合を算出することができます。カスタム ディメンションをユーザーの現在のレベルに設定して Google アナリティクスに送信することができます。ステップは次のとおりです。

  1. User スコープを指定してカスタム ディメンションを作成します。 User スコープを使用するのは、この値をそのユーザーのセッションで保持する必要があるためです。カスタム ディメンションを設定または編集する(ヘルプセンター)をご覧ください。
  2. ユーザーのレベルが変わったときに、カスタム ディメンションの値を更新します。

次のスニペットは、Google アナリティクスでユーザーのステータスを更新する方法を示しています。ここでは、ユーザーレベルのカスタム ディメンションのインデックスが 1 で、ユーザーのレベルが Barren Fields に変更されました。

Android SDK v4

// Set the user level custom dimension when sending a hit to Google Analytics
// such as a screenview or event.
tracker.setScreen("BarrenFields");
tracker.send(new HitBuilders.ScreenViewBuilder()
    .setCustomDimension(1, "Barren Fields")
    .build()
);

iOS SDK v3

// Set the user level custom dimension when sending a hit to Google Analytics
// such as a screenview or event.
[tracker set:kGAIScreenName value:@"BarrenFields"];
[tracker send:[[[GAIDictionaryBuilder createScreenView]
         set:@"Barren Fields"
      forKey:[GAIFields customDimensionForIndex:1]] build]];

Unity 用 Google アナリティクス プラグイン v3

// Set the user level custom dimension when sending a hit to Google Analytics
// such as a screenview or event.
googleAnalytics.LogScreen(new AppViewHitBuilder()
    .SetScreenName("BarrenFields").SetCustomDimension(1, "Barren Fields"));

カスタム ディメンションとカスタム指標に関する デベロッパー ガイド

カスタム ディメンションとカスタム指標のレポート

カスタム ディメンションは、以下にセグメントとして含めて適用できます。

カスタム ディメンションをセグメントとして適用することによって、ゲームの中で特定のレベル にいるユーザーを分析することができます。

ユーザーがタスクを完了するまでにどれくらいの時間がかかるか。 (カスタム速度)

アプリ内で、タスクを完了するのにかかった時間を計測する場合は、Google アナリティクスでカスタム速度を使用して時間に基づく計測を行うことができます。ユーザータイミングはイベントに似ていますが、時間ベースで、categoryvaluename (variable)label を含めることができます。カスタム速度の仕組みについては、サイトの速度についてをご覧ください。

たとえば、ドラゴン キャッチャーで、ユーザーが最初のドラゴンを助け出すのにどれだけかかるかを計測する場合、次のようなコードになります。

Android SDK v4

// Build and send a timing hit.
tracker.send(new HitBuilders.TimingBuilder()
    .setCategory("Barren Fields")
    .setValue(45000)  // 45 seconds.
    .setVariable("First Rescue")
    .setLabel("Dragon")
    .build());

iOS SDK v3

[tracker send:[[GAIDictionaryBuilder createTimingWithCategory:@"Barren Fields"
                                                     interval:@45000   // 45 seconds.
                                                         name:@"First Rescue"
                                                        label:@"Dragon"] build]];

Unity 用 Google アナリティクス プラグイン v3

// Build and send a timing hit.
googleAnalytics.LogTiming("Barren Fields",45000,"First Rescue","Dragon");

カスタム速度に関するデベロッパー ガイド

カスタム速度のレポート

カスタム速度のデータは以下でご確認いただけます。

  • アナリティクス アカデミー - モバイルアプリ解析の基本などを説明する無料のオンライン コースで、アナリティクス スキルをレベルアップすることができます。
  • Collection API / SDK - Google アナリティクスにデータを送信するさまざまな方法を学びます。