Android Google Analytics API v4实时

时间:2014-10-05 19:45:43

标签: android google-analytics google-analytics-api google-analytics-v4

我已经在应用程序中设置了使用谷歌分析V4,我可以看到"屏幕,活跃用户,新用户和顶级设备模型"但是我没有看到" Real-Time"应用程序上的数据或活跃用户。

global_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ga_trackingId">UA-XXXXXX-X</string>
<integer name="ga_sessionTimeout">300</integer>
<bool name="ga_autoActivityTracking">true</bool>
<string name="ga_logLevel">verbose</string>
<integer name="ga_dispatchPeriod">30</integer>
<bool name="ga_dryRun">false</bool>
<screenName name="com.sounds.MainActivity">MainActivity</screenName>
</resources>

app_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ga_trackingId">UA-XXXXXX-X</string>
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<string name="ga_appName">soundsapp</string>
<string name="ga_appVersion">3.4</string>
<bool name="ga_debug">true</bool>
<item name="ga_dispatchPeriod" format="integer" type="integer">120</item>
<string name="ga_sampleFrequency">90</string>
<bool name="ga_anonymizeIp">true</bool>
<bool name="ga_dryRun">false</bool>
<string name="ga_sampleFrequency">100.0</string>
<integer name="ga_sessionTimeout">10</integer>
<string name="com.sounds.MainActivity">MainActivity</string>
</resources>

的AndroidManifest.xml

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="@xml/global_tracker" />

Trackers.java

public class Trackers extends Application {

 private static final String PROPERTY_ID = "UA-XXXXXX-X";
 public static int GENERAL_TRACKER = 0;
 public enum TrackerName {
     APP_TRACKER, // Tracker used only in this app.
     GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
     ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
 }

 public HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

 public Trackers() {
     super();
 }

 public synchronized Tracker getTracker(TrackerName trackerId) {
     if (!mTrackers.containsKey(trackerId)) {
         GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
         Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID): (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker): analytics.newTracker(R.xml.ecommerce_tracker);
         mTrackers.put(trackerId, t);

     }
     return mTrackers.get(trackerId);
   }
 }

活动类

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
Tracker t = ((Trackers)this.getApplication()).getTracker(TrackerName.APP_TRACKER);
t.setScreenName("HomePage");    
    .....
 @Override
  protected void onStart() {
  // TODO Auto-generated method stub

  super.onStart();
  GoogleAnalytics.getInstance(this).reportActivityStart(this);
  //Get an Analytics tracker to report app starts & uncaught exceptions etc.  
  }

  @Override
  protected void onStop() {
  // TODO Auto-generated method stub
  super.onStop();
  //Stop the analytics tracking
  GoogleAnalytics.getInstance(this).reportActivityStop(this);
  }       

1 个答案:

答案 0 :(得分:3)

我遇到了类似的问题,结果证明这是一个夏令时错误。检查分析帐户中的时区。如果您所在区域中的当前时区不正确(您可以使用this site检查该时区的时间),请将时区更改为具有正确时区的其他区域。不要忘记在你的国家移动时钟之后将其改回来。