การวัดผลแคมเปญ - Android SDK

เอกสารนี้แสดงภาพรวมของวิธีวัดผลแคมเปญและ แหล่งที่มาของการเข้าชมด้วย Google Analytics SDK สำหรับ Android v3

ภาพรวม

การวัดผลแคมเปญใน Google Analytics จะช่วยให้ระบุแหล่งที่มาของแคมเปญและแหล่งที่มาของการเข้าชมไปยังกิจกรรมของผู้ใช้ภายในแอปพลิเคชันได้ ตัวเลือกเหล่านี้พร้อมใช้งานสำหรับการระบุแหล่งที่มาของแคมเปญและแหล่งที่มาของการเข้าชมใน Google Analytics SDK สำหรับ Android

ส่วนต่อไปนี้จะอธิบายกรณีและวิธีใช้งานการวัดผลแคมเปญแต่ละประเภทในแอป

พารามิเตอร์แคมเปญ

พารามิเตอร์แคมเปญใช้สำหรับส่งต่อข้อมูลเกี่ยวกับแหล่งที่มาของการเข้าชมและแคมเปญที่นำผู้ใช้มาที่แอปของคุณ

ตารางด้านล่างประกอบด้วยพารามิเตอร์แคมเปญที่ใช้ได้ซึ่งใช้ได้ใน Google Play หรือการวัดผลแคมเปญทั่วไป

พารามิเตอร์ คำอธิบาย ตัวอย่าง
utm_campaign ชื่อแคมเปญ ใช้เพื่อวิเคราะห์คีย์เวิร์ดเพื่อระบุการโปรโมตผลิตภัณฑ์หรือแคมเปญเชิงกลยุทธ์ที่เฉพาะเจาะจง utm_campaign=spring_sale
utm_source แหล่งที่มาของแคมเปญ ใช้สำหรับระบุเครื่องมือค้นหา จดหมายข่าว หรือแหล่งที่มาอื่นๆ utm_source=google
utm_medium สื่อแคมเปญ ใช้เพื่อระบุสื่อ เช่น อีเมลหรือต้นทุนต่อคลิก (CPC) utm_medium=cpc
utm_term คำของแคมเปญ ใช้กับการค้นหาที่เสียค่าใช้จ่ายเพื่อระบุคีย์เวิร์ดสำหรับโฆษณา utm_term=running+shoes
utm_content เนื้อหาแคมเปญ ใช้สำหรับการทดสอบ A/B และโฆษณาที่กำหนดเป้าหมายตามเนื้อหาเพื่อแยกแยะโฆษณาหรือลิงก์ที่ชี้ไปยัง URL เดียวกัน utm_content=logolink
utm_content=textlink
gclid พารามิเตอร์การติดแท็กอัตโนมัติของ Google Ads ซึ่งใช้เพื่อวัดโฆษณา ระบบจะสร้างค่านี้แบบไดนามิกและไม่ควรแก้ไข

การระบุแหล่งที่มาของแคมเปญและแหล่งที่มาของการเข้าชมทั่วไป

หลังจากติดตั้งแอปแล้ว แอปอาจเปิดขึ้นโดยการอ้างอิงจากแคมเปญโฆษณา เว็บไซต์ หรือแอปอื่นๆ ในสถานการณ์นี้ แหล่งที่มาของการเข้าชมที่อ้างอิงหรือแคมเปญการตลาดสามารถระบุแหล่งที่มาจากกิจกรรมของผู้ใช้ในเซสชันต่อๆ ไปได้โดยการตั้งค่าช่องแคมเปญในตัวติดตามโดยตรง

ตัวอย่างเช่น การใช้งานต่อไปนี้จะตรวจสอบ Intent ที่เปิดแอปสําหรับพารามิเตอร์แคมเปญ Google Analytics

package com.example.app;

import com.google.analytics.tracking.android.Fields;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.MapBuilder;
import com.google.analytics.tracking.android.Tracker;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import java.util.Map;

/*
 * An example of how to implement general campaign attribution in Android.
 *
 * If the intent that launched the Activity has a URI, parse it for campaign
 * parameters and send the referring data to Google Analytics.
 */
public class MainActivity extends Activity {

  private static final String GA_PROPERTY_ID = "UA-XXXX-Y";
  private static final String SCREEN_LABEL = "Home Screen";

  // This examples assumes the use of Google Analytics campaign
  // "utm" parameters, like "utm_source".
  private static final String CAMPAIGN_SOURCE_PARAM = "utm_source";

  Tracker mTracker;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mTracker = GoogleAnalytics.getInstance(this).getTracker(GA_PROPERTY_ID);
  }

  @Override
  public void onStart() {
    super.onStart();

    // Set screen name on tracker so that all subsequent hits will use this
    // value.
    mTracker.set(Fields.SCREEN_NAME, SCREEN_LABEL);

    // Get the intent that started this Activity.
    Intent intent = this.getIntent();
    Uri uri = intent.getData();

    // Send a screenview using any available campaign or referrer data.
    MapBuilder.createAppView().setAll(getReferrerMapFromUri(uri));
  }

  /*
   * Given a URI, returns a map of campaign data that can be sent with
   * any GA hit.
   *
   * @param uri A hierarchical URI that may or may not have campaign data
   *     stored in query parameters.
   *
   * @return A map that may contain campaign or referrer
   *     that may be sent with any Google Analytics hit.
   */
  Map<String,String> getReferrerMapFromUri(Uri uri) {

    MapBuilder paramMap = new MapBuilder();

    // If no URI, return an empty Map.
    if (uri == null) { return paramMap.build(); }

    // Source is the only required campaign field. No need to continue if not
    // present.
    if (uri.getQueryParameter(CAMPAIGN_SOURCE_PARAM) != null) {

      // MapBuilder.setCampaignParamsFromUrl parses Google Analytics campaign
      // ("UTM") parameters from a string URL into a Map that can be set on
      // the Tracker.
      paramMap.setCampaignParamsFromUrl(uri.toString());

     // If no source parameter, set authority to source and medium to
     // "referral".
     } else if (uri.getAuthority() != null) {

       paramMap.set(Fields.CAMPAIGN_MEDIUM, "referral");
       paramMap.set(Fields.CAMPAIGN_SOURCE, uri.getAuthority());

     }

     return paramMap.build();
  }
}

หรือหากมีข้อมูลแคมเปญในรูปแบบอื่นที่ไม่ใช่พารามิเตอร์แคมเปญ Google Analytics คุณอาจตั้งค่าข้อมูลดังกล่าวใน Map แล้วส่งด้วยตนเองได้โดยทำดังนี้

// May return null if EasyTracker has not yet been initialized with a property ID.
EasyTracker easyTracker = EasyTracker.getInstance(this);
easyTracker.set(Fields.SCREEN_NAME, "Home Screen");

// In this example, campaign information is set using a Map, rather than
// a url string with Google Analytics campaign parameters.
// Note that Fields.CAMPAIGN_KEYWORD is not necessary for this campaign.
HashMap<String, String> campaignData = new HashMap<String, String>();
campaignData.put(Fields.CAMPAIGN_SOURCE, "email");
campaignData.put(Fields.CAMPAIGN_MEDIUM, "email marketing");
campaignData.put(Fields.CAMPAIGN_NAME, "summer_campaign");
campaignData.put(Fields.CAMPAIGN_CONTENT, "email_variation_1");

MapBuilder paramMap = MapBuilder.createAppView();

// Campaign data sent with this hit.
// Note that the campaign data is set on the Map, not the tracker.
easyTracker.send(paramMap
    .setAll(campaignData).build()
);

การระบุแหล่งที่มาของแคมเปญใน Google Play

การวัดผลแคมเปญของ Google Play ช่วยให้คุณเห็นว่าแคมเปญและแหล่งที่มาของการเข้าชมใดที่ส่งผู้ใช้ไปดาวน์โหลดแอปของคุณจาก Google Play Store ขอแนะนำให้นักพัฒนาแอปทุกรายใช้การวัดผลแคมเปญ ของ Google Play Store

การใช้การระบุแหล่งที่มาของแคมเปญใน Google Play

เมื่อดาวน์โหลดแอปจาก Google Play Store แอป Play Store จะประกาศ INTENT_REFERRER ไปยังแอประหว่างการติดตั้ง Intent นี้มีค่าพารามิเตอร์ referrer ของลิงก์ที่ใช้เข้าถึงหน้า Google Play Store ของแอป หากมี

หากต้องการระบุแหล่งที่มาของการดาวน์โหลดแอปในแคมเปญ คุณต้องเพิ่มพารามิเตอร์ referrer ลงในลิงก์ที่ชี้ไปยัง Google Play Store และเพิ่ม BroadcastReceiver ลงในแอปเพื่อรับและตั้งค่าข้อมูลแคมเปญที่อยู่ใน Intent บนเครื่องมือติดตามของ Google Analytics

ขอแนะนำให้นักพัฒนาแอปส่วนใหญ่ใช้ BroadcastReceiver ที่มาพร้อมกับ SDK วิธีวัดแคมเปญ Google Play Store โดยใช้ตัวรับที่รวมไว้

1. เพิ่มตัวรับสัญญาณ Google Analytics ลงในไฟล์ AndroidManifest.xml หากต้องการเพิ่มตัวรับสัญญาณ Google Analytics ลงในไฟล์ Manifest ให้คัดลอกและวางมาร์กอัปต่อไปนี้

<!-- Used for Google Play Store Campaign Measurement-->;
<service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />
<receiver android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver" android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

2. เพิ่มพารามิเตอร์แคมเปญ Google Analytics ลงใน URL ของ Google Play

จากนั้น เพิ่มพารามิเตอร์ referrer ลงใน URL ที่จะลิงก์กับ Google Play Store โดยตรง แล้วกำหนดค่าของพารามิเตอร์นั้นเป็นสตริงพารามิเตอร์แคมเปญ Google Analytics ที่อธิบายแหล่งที่มา ดังตัวอย่างต่อไปนี้

https://play.google.com/store/apps/details?id=com.example.app
&referrer=utm_source%3Dgoogle
%26utm_medium%3Dcpc
%26utm_term%3Dpodcast%252Bapps
%26utm_content%3DdisplayAd1
%26utm_campaign%3Dpodcast%252Bgeneralkeywords

หากต้องการดูวิธีสร้างสตริงพารามิเตอร์แคมเปญ ให้ใช้เครื่องมือสร้าง URL ของ Google Play หรือดูที่ส่วนข้อมูลอ้างอิงพารามิเตอร์แคมเปญ

เครื่องมือสร้าง URL ของ Google Play

ใช้เครื่องมือด้านล่างเพื่อสร้าง URL สำหรับการวัดผลแคมเปญของ Google Play