我尝试输入我的属性ID,但这似乎并不正确。这是我到目前为止所做的。我计划在我的活动的onCreate()方法中从我的AnalyticsTracker1类创建一个实例。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tracker = new AnalyticsTracker1();
tracker.getTracker(UA-60706130-1);
}
这是AnalyticsTracker1类
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import java.util.HashMap;
public class AnalyticsTracker1 extends Application {
private static final String PROPERTY_ID = "UA-XXXXXXXX-1";
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
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.
}
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):null;
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
答案 0 :(得分:1)
我在Google分析的getTracker参数中添加了什么
您应该在扩展Application
。
例如,对于发送屏幕视图,您可以使用onCreate()
方法以此方式调用
发送屏幕视图
要发送屏幕视图,请在跟踪器上设置屏幕字段值,然后发送匹配:
// Get tracker.
Tracker t = ((AnalyticsSampleApp) this.getApplication()).getTracker(
TrackerName.APP_TRACKER);
// Set screen name.
t.setScreenName(screenName);
// Send a screen view.
t.send(new HitBuilders.ScreenViewBuilder().build());
价: https://developers.google.com/analytics/devguides/collection/android/v4/advanced#sampling