在你的Android应用程序中集成Google Analytics,帮助你分析用户的访问量
** Java Code ** // Google Analytics private Tracker mGaTracker; private GoogleAnalytics mGaInstance; // Call this method from onCreate() private void initGATracker() { mGaInstance = GoogleAnalytics.getInstance(this); mGaTracker = mGaInstance.getTracker(getResources().getString( R.string.ga_trackingId)); EasyTracker.getInstance().setContext(getApplicationContext()); } @Override protected void onStart() { super.onStart(); EasyTracker.getInstance().activityStart(this); } @Override protected void onStop() { super.onStop(); EasyTracker.getInstance().activityStop(this); } // sample to how to use it, add it where you want to track mGaTracker.sendEvent("Category", "Action", Label, null); ------------------------------------------------------------------------------------------------------------ ** create res/values/analytics.xml ** ------------------------------------------------------------------------------------------------------------ <?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="https://schemas.android.com/tools" tools:ignore="TypographyDashes"> <!-- Replace placeholder ID with your tracking ID --> <string name="ga_trackingId">UA-XXXX</string> <!-- Enable automatic activity tracking --> <bool name="ga_autoActivityTracking">true</bool> <!-- Enable automatic exception tracking --> <bool name="ga_reportUncaughtExceptions">true</bool> <!-- The screen names that will appear in your reporting --> <string name="package_name.MainActivity">Home Activity</string> <!-- The inverval of time after all the collected data should be sent to the server, in seconds. --> <integer name="ga_dispatchPeriod">30</integer> <!-- Enable debugging --> <bool name="ga_debug">false</bool> <!-- Automatically send all uncaught exceptions in your app using EasyTracker --> <bool name="ga_reportUncaughtExceptions">true</bool> </resources> // see http://androidsnippets.com/google-analytics