我正在尝试使用 Google Analytics 工具跟踪我的应用程序使用情况。但我的 Google Analytics(分析)帐户没有显示访客/访客。我已经多次使用我的应用程序。我也设置了按钮单击事件。但它什么也没显示。我也有一个有效的密钥。
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class GoogleAnalysis extends Activity {
GoogleAnalyticsTracker tracker;
GoogleAnalyticsTracker mGATracker;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* try{ mGATracker = GoogleAnalyticsTracker.getInstance();
mGATracker.startNewSession(" UA-xxxxx-x", this);
mGATracker.trackPageView( "/SettingsMangerActivity" ); } catch(
Exception error ) { Log.e( "<YOUR_TAG>", "onCreate: " +
error.toString() ); }
*/
tracker = GoogleAnalyticsTracker.getInstance();
tracker.startNewSession(" UA-30927539-1", this);
setContentView(R.layout.googleanlytics);
Button createEventButton = (Button) findViewById(R.id.NewEventButton);
createEventButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tracker.trackPageView("/SettingsMangerActivity");
tracker.trackEvent("Clicks", "Button", "Share Files", 0);
}
});
Button createPageButton = (Button) findViewById(R.id.NewPageButton);
createPageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tracker.setCustomVar(1, "Navigation Type", "Button click", 2);
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();
}
}