我正在尝试通过 Google 配置在我的 Android 应用程序中使用 Google Analytics
- 在我的项目中添加 .jar
将其插入 AndroidManifest
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
在我的java文件中添加这个
公共类 MainActivity 扩展 Activity {
GoogleAnalyticsTracker tracker; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tracker = GoogleAnalyticsTracker.getInstance(); tracker.startNewSession("My-UA–XXXXXXXX", this); setContentView(R.layout.main); Button createEventButton = (Button)findViewById(R.id.NewEventButton); createEventButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tracker.trackEvent( "Clicks", // Category "Button", // Action "clicked", // Label 77); // Value } }); setContentView(R.layout.main); Button createPageButton = (Button)findViewById(R.id.NewPageButton); createPageButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Add a Custom Variable to this pageview, with name of "Medium" and value "MobileApp" and // scope of session-level. tracker.setCustomVar(1, "Navigation Type", "Button click", 2); // Track a page view. This is probably the best way to track which parts of your application // are being used. // E.g. // tracker.trackPageView("/help"); to track someone looking at the help screen. // tracker.trackPageView("/level2"); to track someone reaching level 2 in a game. // tracker.trackPageView("/uploadScreen"); to track someone using an upload screen. tracker.trackPageView("/testApplicationHomeScreen"); } }); Button quitButton = (Button)findViewById(R.id.QuitButton); quitButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); Button dispatchButton = (Button)findViewById(R.id.DispatchButton); dispatchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Manually start a dispatch, not needed if the tracker was started with a dispatch // interval. tracker.dispatch(); } }); } @Override protected void onDestroy() { super.onDestroy(); // Stop the tracker when it is no longer needed. tracker.stopSession(); } }
==> 没关系,没有错误,编译和执行,但我昨天(更多 24 小时)创建了我的 ua 帐户,我的谷歌分析面板中没有任何内容。
我的问题:我的代码中有错误还是我想再次等待?实时流量适用于 Android 应用程序(如传统网站)???我没有关于实时流量(当我玩我的应用程序时,我想显示使用我的应用程序的人数)和已保存流量(查看页面、时间)的信息
感谢您的回复并原谅我糟糕的英语:)
再见
更新 1: 我用过这个教程:http ://www.xatik.com/2012/03/27/how-to-use-google-analytics-in-android-applications/我有这个日志猫:
04-07 14:21:59.669: INFO/GoogleAnalyticsTracker(864): Host: www.google-analytics.com
04-07 14:21:59.669: INFO/GoogleAnalyticsTracker(864): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.2; en-us; sdk Build/FRF91)
04-07 14:21:59.669: INFO/GoogleAnalyticsTracker(864): GET /__utm.gif?utmwv=4.8.1ma&utmn=235327630&utme=8(1!Navigation%20Type)9(1!Button%20click)11(1!2)&utmcs=UTF-8&utmsr=240x320&utmul=en-US&utmp=%2FtestApplicationHomeScreen&utmac=BLIBLUBLIBLO–1&utmcc=more_and_more
正在进行中,但我的实时分析面板中没有任何内容......我在我的项目中添加了 EasyTracker .jar 这是我的活动代码:
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
import com.google.android.apps.analytics.easytracking.EasyTracker;
import com.google.android.apps.analytics.easytracking.TrackedActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends TrackedActivity {
GoogleAnalyticsTracker tracker;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button quitButton = (Button)findViewById(R.id.QuitButton);
quitButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EasyTracker.getTracker().trackEvent("ButtonClick", "MyButtonName", "", 0);
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
//How can i stop the tracking onDestroy ???
}
}