我正在尝试在我的Android应用程序中使用Google Analytics Google Configuration
将其插入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();
}
}
==&GT;它没关系,没有错误,编译和执行但我昨天创建了我的帐户(更多24小时),我的谷歌分析面板中没有任何内容。
我的问题:我的代码中是否有错误或者我想再等一下? Android应用程序的实时流量工作(如tradicional网站)??? 我没有关于Live trafic的信息(当我玩我的应用程序时,我想显示使用我的应用程序的人数)和Saved trafic(查看页面,时间)
感谢您的回复,请原谅我可怜的英语:)
再见
更新1: 我已经使用了这个tuto:http://www.xatik.com/2012/03/27/how-to-use-google-analytics-in-android-applications/我已经在我的Logcat中得到了这个:
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
正在进行中,但我的Live Analytics面板中没有任何内容.... 我在我的项目中添加了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 ???
}
}
答案 0 :(得分:8)
我知道这已经有几个月了,但我会给予回应以帮助他人。我是编写OP的Update 1中引用的指南的人。我最初遇到的一个问题是我在手机上使用自定义ROM。许多自定义ROM都修改了“主机”文件,这些文件会阻止应用访问展示广告,或者阻止向Google Analytics发送数据。如果您的手机上有自定义ROM,则可以查看“主机”文件,查看其中是否列出了Google Analytics。最快的方法是在计算机上的文本编辑器中打开文件。要做到这一点:
这应该允许您的手机将数据发送到Google Analytics。我会更新我的指南,将其包含在某处。