0

我已经在应用程序中设置了使用谷歌分析 V4 的所有内容,我可以看到“屏幕、活跃用户、新用户和顶级设备模型”,但在应用程序上看不到“实时”数据或活跃用户。

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" />

跟踪器.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);
  }       
4

1 回答 1

3

我有一个类似的问题,结果证明是夏令时错误。检查您的分析帐户中的时区。如果它不是您所在地区的正确当前时区(您可以使用此站点检查该时区的时间),请将时区更改为具有您正确时区的另一个地区。在他们确实在您的国家/地区移动时钟后,请不要忘记将其改回。

于 2014-10-22T12:59:17.667 回答