我的目标是使用Google Analytics事件跟踪计算按钮点击次数。
如何计算按钮点击次数以及哪个用户(和设备)点击了此按钮?
我正在使用此代码:
public class TestActivity extends Activity {
GoogleAnalyticsTracker tracker;
Button clickBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tracker = GoogleAnalyticsTracker.getInstance();
tracker.startNewSession("UA-XXXXXXXX-1", 30, this);
tracker.setDebug(true);
clickBtn = (Button) findViewById(R.id.click);
setContentView(R.layout.main);
final Button createEventButton = (Button) findViewById(R.id.NewEventButton);
createEventButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tracker.trackEvent("Clicks", // Category
"Button", // Action
"" + clickBtn, // Label
77); // Value
tracker.trackEvent("Clicks", "" + createEventButton, "Easy", 1);
tracker.trackEvent("Completions", "Game-Deaths",
"Hard-Level-One", 15);
tracker.trackEvent("Die", "Easy", " Two", 15);
tracker.trackTransactions();
}
});
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"
tracker.setCustomVar(1, "Medium", "Mobile App");
// 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();
}
}
答案 0 :(得分:9)
在GA控制台中,您可以获得多个号码。 (参与 - >活动)
让我们通过示例解释一下,如果你将这一行放在按钮上点击:
tracker.trackEvent("Completions", "Game-Deaths",
"Hard-Level-One", 15);
用户点击了此按钮两次。
您将获得此统计信息:
希望你能清楚。
答案 1 :(得分:0)
请在lib文件夹中添加Google analytics jar文件。 (在lib文件夹中复制jar文件。&项目属性 - > Java构建路径 - >库 - >添加jar) libGoogleAnalytics.jar
jar文件链接: - https://developers.google.com/analytics/devguides/collection/android/resources
我希望解决你添加jar文件的问题。
谢谢。
答案 2 :(得分:0)
我认为您正在使用Google Analytics旧库,尝试使用新的V2库,它易于使用,并且有良好的文档支持。以下是使用v2版本进行事件跟踪的链接:https://developers.google.com/analytics/devguides/collection/android/v2/events
答案 3 :(得分:0)
要向Google Analytics发送活动,请使用此处显示的tracker.send(MapBuilder.createEvent(...).build())
- Event tracking in Google Analytics SDK V3。