1

我之前使用过 Google Analytics v2,可以使用以下代码发送应用名称、应用版本并设置 anbonimize Ip:

        m_GaTracker.setAnonymizeIp(true);
        m_GaTracker.setAppName("MyRemote");
        m_GaTracker.setAppVersion(m_appVersion);

m_GaTrackerGoogle Analytics Tracker 的实例在哪里。

我现在正在迁移到 V3,但此代码不再起作用。我收到此错误:

The method setAnonymizeIp(boolean) is undefined for the type Tracker

如何解决这个问题,或者有没有其他方法可以使用 Google Analytics v3 发送这些值?

已经检查过了,但它没有用!

4

1 回答 1

3

我相信现在您需要使用该set方法。

Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-XXXX-Y");

// Values set directly on a tracker apply to all subsequent hits.
tracker.set(Fields.ANONYMIZE_IP, true);

在https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference有一个字段参考。(它是为 analytics.js 编写的,v3 分析旨在与之保持一致。)

您还可以通过反编译 libGoogleAnalyticsServices.jar 来查看 Fields 字符串列表:

public final class Fields
{
  public static final String ANONYMIZE_IP = "&aip";
  public static final String HIT_TYPE = "&t";
  public static final String SESSION_CONTROL = "&sc";
  public static final String NON_INTERACTION = "&ni";
  public static final String DESCRIPTION = "&cd";
  public static final String SCREEN_NAME = "&cd";
  public static final String LOCATION = "&dl";
  public static final String REFERRER = "&dr";
  public static final String PAGE = "&dp";
  public static final String HOSTNAME = "&dh";
  public static final String TITLE = "&dt";
  public static final String LANGUAGE = "&ul";
  public static final String ENCODING = "&de";
  public static final String SCREEN_COLORS = "&sd";
  public static final String SCREEN_RESOLUTION = "&sr";
  public static final String VIEWPORT_SIZE = "&vp";
  public static final String CLIENT_ID = "&cid";
  public static final String CAMPAIGN_NAME = "&cn";
  public static final String CAMPAIGN_SOURCE = "&cs";
  public static final String CAMPAIGN_MEDIUM = "&cm";
  public static final String CAMPAIGN_KEYWORD = "&ck";
  public static final String CAMPAIGN_CONTENT = "&cc";
  public static final String CAMPAIGN_ID = "&ci";
  public static final String EVENT_CATEGORY = "&ec";
  public static final String EVENT_ACTION = "&ea";
  public static final String EVENT_LABEL = "&el";
  public static final String EVENT_VALUE = "&ev";
  public static final String SOCIAL_NETWORK = "&sn";
  public static final String SOCIAL_ACTION = "&sa";
  public static final String SOCIAL_TARGET = "&st";
  public static final String TIMING_VAR = "&utv";
  public static final String TIMING_VALUE = "&utt";
  public static final String TIMING_CATEGORY = "&utc";
  public static final String TIMING_LABEL = "&utl";
  public static final String APP_NAME = "&an";
  public static final String APP_ID = "&aid";
  public static final String APP_INSTALLER_ID = "&aiid";
  public static final String APP_VERSION = "&av";
  public static final String EX_DESCRIPTION = "&exd";
  public static final String EX_FATAL = "&exf";
  public static final String CURRENCY_CODE = "&cu";
  public static final String TRANSACTION_ID = "&ti";
  public static final String TRANSACTION_AFFILIATION = "&ta";
  public static final String TRANSACTION_SHIPPING = "&ts";
  public static final String TRANSACTION_TAX = "&tt";
  public static final String TRANSACTION_REVENUE = "&tr";
  public static final String ITEM_SKU = "&ic";
  public static final String ITEM_NAME = "&in";
  public static final String ITEM_CATEGORY = "&iv";
  public static final String ITEM_PRICE = "&ip";
  public static final String ITEM_QUANTITY = "&iq";
  public static final String TRACKING_ID = "&tid";
  public static final String SAMPLE_RATE = "&sf";
  public static final String JAVA_ENABLED = "&je";
  public static final String FLASH_VERSION = "&fl";
  public static final String USE_SECURE = "useSecure";
  static final String API_VERSION = "&v";
  static final String CLIENT_VERSION = "&_v";
  static final String USAGE_TRACKING = "&_u";
  static final String QUEUE_TIME = "&qt";
  static final String HIT_TIME = "&ht";
  static final String CACHE_BUSTER = "&z";
  static final String GCLID = "&gclid";
  static final String DCLID = "&dclid";
  static final String GMOB_T = "&gmob_t";
  public static final String ANDROID_APP_UID = "AppUID";

用于分析的 android 文档可能会更好。

于 2013-10-03T19:24:50.730 回答