本文件適合行動開發人員,說明如何使用 Google Analytics (分析) 評估使用者互動,並回答應用程式使用情形的相關問題。
簡介
行動應用程式專用 Google Analytics (分析) 提供評估使用者互動的平台,方便您進一步瞭解應用程式的使用者參與度,並進行最佳化。
Google Analytics (分析) 的預設導入會自動提供以下有關應用程式的資訊:
- 使用者人數和工作階段數
- 工作階段持續時間
- 作業系統
- 裝置型號
- 地理位置
本指南將說明如何實作其他 Google Analytics (分析) 功能,進一步瞭解使用者及其行為。
事前準備
在參閱本指南來設定 Google Analytics (分析) 行動應用程式之前:
- 根據目標平台安裝 SDK:
- 查看行動應用程式分析設定最佳做法
總覽
蜻蜓
本指南使用範例應用程式,逐步說明如何導入其他 Google Analytics (分析) 功能。此應用程式稱為 Dragon Catcher,具有下列遊戲特色:
- 關卡包括玩家、龍、圍欄區域、果園和樹木
- 玩家的目標是把它們移動到圍欄區,捕獲惡龍
- 玩家可以瀏覽關卡的不同區域,以及果樹或魔術樹等物體
- 玩家抓到所有龍蝦後,就會晉升到下一個關卡
- 玩家會在第一個關卡啟動遊戲,該關卡的名稱是 Barren Fields。
使用 Google Analytics (分析),您可以解答一些關於 Dragon Catcher 的使用者行為問題:
- 使用者採取了哪些動作?(事件)
- 使用者在我的應用程式中花費多少錢? (電子商務)
- 使用者是否達成我的應用程式目標?(目標)
- 有特定特徵的使用者會有什麼行為?(自訂維度/指標)
- 使用者需要多久才能完成工作?(自訂時間)
本文件的其他部分說明如何為 Dragon Catcher 遊戲實作 Google Analytics (分析) 功能,以獲得這些問題的答案。
使用者採取了哪些動作?(事件)
如果您想在應用程式中追蹤重要動作,可以在 Google Analytics (分析) 中使用事件來描述這項動作。事件由四個參數組成:category
、action
、label
和 value
。
例如,在 Dragon Catcher 中,當使用者搜救龍或造訪特定關卡中的特定區域時,我們需要使用事件來評估重要動作。以下程式碼片段說明如何在 Google Analytics (分析) 中評估這一點。
Android SDK
// 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
// 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 Analytics (分析) 外掛程式
// 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 Analytics (分析) 中的事件來評估玩家「成就」。舉例來說,如要評估拯救 5 隻龍的成就,系統會記錄玩家所獲勝的龍數量,並在玩家達到門檻,將事件傳送至 Google Analytics (分析) 時:
Android SDK
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
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 Analytics (分析) 外掛程式
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); } }
活動開發人員指南
事件報表
事件資料可在下列國家/地區查看:
- 網頁介面位於「行為」>「事件」>「熱門事件」
- 自訂報表
- Core Reporting API
使用者在我的應用程式中花費多少錢?(加強型電子商務)
如要評估使用者的應用程式內購,則可使用電子商務追蹤來追蹤購買情形,並瞭解相關產品效能和使用者行為。電子商務追蹤可用來評估特定商品或虛擬貨幣的購買情形。
舉例來說,在 Dragon Catcher 中,為了評估某些項目的購買情形,交易資料會透過事件傳送至 Google Analytics (分析):
Android SDK
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
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 Analytics (分析) 外掛程式
// 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 Analytics (分析) 時評估實際貨幣的匯率,當使用者以虛擬貨幣購買商品時,使用事件進行評估。例如:
Android SDK
/** * 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
/** * 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 *viewBuilder = [GAIDictionaryBuilder createScreenView]; // Add the transaction data to the screenview. [viewBuilder setProductAction:productAction]; [viewBuilder addProduct:product]; // Send the transaction with the screenview. [tracker set:kGAIScreenName value:@"In-Game Store"]; [tracker send:[viewBuilder build]]; /** * When the user purchases an item using the virtual currency (Gems) send an * event to measure this in Google Analytics. */ GAIDictionaryBuilder *eventBuilder = [GAIDictionaryBuilder createEventWithCategory:@"In-Game Store" action:@"Purchase" label:@"Sword" value:@35]; [tracker send:[eventBuilder build]];
Unity 適用的 Google Analytics (分析) 外掛程式
// 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);
加強型電子商務適用的開發人員指南
加強型電子商務報表
電子商務資料目前適用於:
使用者是否達成我的應用程式目標?(目標)
如果您希望使用者完成應用程式的特定目標,可以使用 Google Analytics (分析) 中的「目標」定義並評估這些目標。舉例來說,目標可以是讓使用者達成特定遊戲關卡,或是購買商品。如要進一步瞭解目標的運作方式,請參閱「目標簡介 (說明中心)」一文。
在 Dragon Catcher 遊戲中,您可以設定將每次購買交易的事件傳送至 Google Analytics (分析),以評估完成應用程式內購的時間。目標無須任何額外程式碼,可在網頁介面管理員中使用下列參數定義:
- 目標類型 (等於):事件
- 類別 (等於):遊戲內商店
- 動作 (等於):購買
- 使用事件價值做為轉換的目標價值:是
目標報表
目標資料適用於:
- 位於「轉換」>「目標」>「總覽」下的網頁介面
- 自訂報表
- Core Reporting API
有特定特徵的使用者會有什麼行為?(自訂維度和指標)
如要追蹤具有特定屬性/特徵/中繼資料的使用者,則可使用自訂維度將這類資料傳送至 Google Analytics (分析) 並進行分析。如要進一步瞭解自訂維度的運作方式,請參閱自訂維度和指標功能參考資料。
例如,您可以在 Dragon Catcher 中查看第一層和第二層級等使用者的人數百分比。您可以使用使用者目前層級設定自訂維度,並傳送至 Google Analytics (分析)。步驟如下:
- 建立具有
User
範圍的自訂維度。 使用User
範圍,因為這個值應保留在該使用者的所有工作階段中。請參閱「設定或修改自訂維度 (說明中心)」一文。 - 在使用者層級發生變更時更新自訂維度值。
以下程式碼片段說明如何在 Google Analytics (分析) 中更新使用者的狀態,其中使用者層級的自訂維度索引是 1
,且使用者層級已變更為 Barren Fields
:
Android SDK
// Set the user level custom dimension when sending a hit to Google Analytics // such as a screenview or event. tracker.setScreenName("BarrenFields"); tracker.send(new HitBuilders.ScreenViewBuilder() .setCustomDimension(1, "Barren Fields") .build() );
iOS SDK
// 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 Analytics (分析) 外掛程式
// 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"));
自訂維度和指標的開發人員指南
自訂維度和指標的報表
自訂維度可以納入及套用為區隔,以便達成下列目的:
- 網頁介面中大部分的標準報表
- 自訂報表
- Core Reporting API
將自訂維度套用為區隔,即可分析目前在遊戲中特定關卡的使用者。
使用者需要多久才能完成工作? (自訂時間)
如要評估應用程式中完成特定操作所需的時間,您可以在 Google Analytics (分析) 中使用使用者時間進行時間型評估。使用者載入時間與事件類似,但時間是以時間為準,其中可能包含 category
、value
、name (variable)
和 label
。如要瞭解使用者載入時間的運作方式,請參閱「網站速度簡介」一文。
例如,在 Dragon Catcher 中,測量使用者需要多久時間才能救援第一個龍,然後傳送如下內容:
Android SDK
// 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
[tracker send:[[GAIDictionaryBuilder createTimingWithCategory:@"Barren Fields" interval:@45000 // 45 seconds. name:@"First Rescue" label:@"Dragon"] build]];
Unity 適用的 Google Analytics (分析) 外掛程式
// Build and send a timing hit. googleAnalytics.LogTiming("Barren Fields",45000,"First Rescue","Dragon");
自訂時間的開發人員指南
自訂時間的報表
下列國家/地區的使用者可取得自訂時間資料:
- 位於「行為」>「應用程式速度」下方的網頁介面
- 自訂報表
- Core Reporting API
相關資源
- Analytics (分析) 學習中心:透過行動應用程式數據分析基礎知識等免費線上課程,精進 Analytics (分析) 相關技能。
- 收集 API 和 SDK: 瞭解傳送資料至 Google Analytics (分析) 的所有方式