Android Google Analytics xml file
I agree with you. New documentation is not so helpful.
Here is my Application class and all you need is that, you don't need any other thing for basic integration. Even not need a xml. Use this tracker object where you want.
import android.app.Activity;
import android.content.Context;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import java.io.IOException;
public class Application extends android.app.Application {
public static GoogleAnalytics analytics;
public static Tracker tracker;
@Override
public void onCreate() {
super.onCreate();
analytics = GoogleAnalytics.getInstance(this);
analytics.setLocalDispatchPeriod(1800);
tracker = analytics.newTracker("UA-XXXXXX-X");
tracker.enableExceptionReporting(true);
tracker.enableAdvertisingIdCollection(true);
tracker.enableAutoActivityTracking(true);
}
}
Also keep 'com.google.android.gms:play-services-analytics:7.3.0' dependency in your "build.gradle".
Edit: i think my answer is not valid anymore. Don't force and just use json file :)
With V4 of Google Analytics, Google has implemented various changes in the approach. They generate a google-services.json
file which you download and add to your project; here are the definitive guides on the various steps
https://developers.google.com/analytics/devguides/collection/android/v4/start and
https://developers.google.com/analytics/devguides/collection/android/v4/
However, like the rest of the people here, when I used the sample code for the Application Object from Google there was a compilation error for R.xml.global_tracker
. In Android Studio I decided to 'clean' the project and that did the trick. However the magic works, the xml object is now generated as part of R.java
For reference: I'm running Android Studio 2.2.3 on OSX. Presumably the fix should work on future instances and other OS's until Google change their practices again.