我试图在我的Android应用中集成谷歌分析。它没有奏效。我不知道问题出在哪里。这是代码
Main_activity:
Tracker t = ((MyApplication) getApplication()).getTracker(TrackerName.APP_TRACKER);
t.enableAdvertisingIdCollection(true);
global_tracker.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ga_trackingId">UA-57284840-1</string>
<integer name="ga_sessionTimeout">300</integer>
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<screenName name="info.saidtagnit.hikamal3odama.QuotesActivity">Quotes_Activity</screenName>
<screenName name="info.saidtagnit.hikamal3odama.AuthorsActivity">Authors_Activity</screenName>
</resources>
app_tracker.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" >
<!-- The apps Analytics Tracking Id -->
<string name="ga_trackingId">UA-57284840-1</string>
<!-- Percentage of events to include in reports -->
<string name="ga_sampleFrequency">100.0</string>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- catch and report uncaught exceptions from the app -->
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- How long a session exists before giving up -->
<integer name="ga_sessionTimeout">-1</integer>
<!-- If ga_autoActivityTracking is enabled, an alternate screen name can be specified to
substitute for the full length canonical Activity name in screen view hit. In order to
specify an alternate screen name use an <screenName> element, with the name attribute
specifying the canonical name, and the value the alias to use instead. -->
<screenName name="info.saidtagnit.hikamal3odama.QuotesActivity">Quotes_Activity</screenName>
<screenName name="info.saidtagnit.hikamal3odama.AuthorsActivity">Authors_Activity</screenName>
</resources>
这是MyApplication类:
package info.saidtagnit.hikamal3odama;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import java.util.HashMap;
public class MyApplication extends Application {
// The following line should be changed to include the correct property id.
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.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
private static final String PROPERTY_ID = "UA-57284840-1";
//Logging TAG
private static final String TAG = "MyApp";
public static int GENERAL_TRACKER = 0;
public MyApplication() {
super();
}
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID):analytics.newTracker(R.xml.global_tracker);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
答案 0 :(得分:0)
您的会话超时-1可能会导致一些问题。
尝试从跟踪器定义中删除以下行: -1
还有两个单独的跟踪器,可以将数据上传到同一个跟踪器ID&#34; UA-57284840-1&#34;可能会导致重复上传并在报告中加倍一些数字。我建议为每个跟踪器ID使用单个跟踪器。