我正在尝试将Google Analytics包含到我的Android项目中。上次我使用它是V2并且效果很好。
现在我遇到了这个问题
11-10 20:15:35.493 1957-1957/com.xxx W/GAv4: Int xml configuration name not recognized: ga_sessionTimeout
11-10 20:15:35.508 1957-1957/com.xxx W/GAv4: Bool xml configuration name not recognized: ga_autoActivityTracking
11-10 20:15:35.508 1957-1957/com.xxx W/GAv4: String xml configuration name not recognized: ga_trackingId
global_tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<integer name="ga_sessionTimeout">300</integer>
<bool name="ga_autoActivityTracking">true</bool>
<string name="ga_trackingId">UA-10009718-55</string>
<!-- the Local LogLevel for Analytics -->
<string name="ga_logLevel">verbose</string>
<!-- how often the dispatcher should fire -->
<integer name="ga_dispatchPeriod">30</integer>
<!-- Treat events as test events and don't send to google -->
<bool name="ga_dryRun">false</bool>
<screenName name=".MainActivity">MainActivity</screenName>
</resources>
app_tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<string name="ga_trackingId">UA-10009718-55</string>
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<string name="ga_appName">GoogleAnalyticsApp</string>
<string name="ga_appVersion">1.1.3</string>
<bool name="ga_debug">true</bool>
<item name="ga_dispatchPeriod" format="integer" type="integer">120</item>
<bool name="ga_anonymizeIp">true</bool>
<bool name="ga_dryRun">false</bool>
<string name="ga_sampleFrequency">100.0</string>
<integer name="ga_sessionTimeout">-1</integer>
<string name="com.xxx">Sounds</string>
</resources>
类
package com.xxx;
import java.util.HashMap;
import android.app.Application;
import android.util.Log;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
public class GoogleAnalyticsApp extends Application {
private static final String PROPERTY_ID = "UA-10009718-55";
public static int GENERAL_TRACKER = 0;
public enum TrackerName {
APP_TRACKER, GLOBAL_TRACKER, ECOMMERCE_TRACKER,
}
public HashMap mTrackers = new HashMap();
public GoogleAnalyticsApp() {
super();
}
public synchronized Tracker getTracker(TrackerName appTracker) {
if (!mTrackers.containsKey(appTracker)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (appTracker == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID) : (appTracker == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.app_tracker) : analytics.newTracker(R.xml.ecommerce_tracker);
// Tracker t = analytics.newTracker(PROPERTY_ID);
mTrackers.put(appTracker, t);
}
return (Tracker) mTrackers.get(appTracker);
}
}
也为AndroidManifest添加了必要的行。
<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" />
<!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background
dispatching on non-Google Play devices -->
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver" android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.AnalyticsService" android:enabled="true" android:exported="false" />
<!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
installation campaign reporting -->
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
当我启用Dry Run时,我会在日志中看到它收集ID和其他发送信息。但是当残疾人没有任何反应时。