Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Google Analytics availability in Google Play Services?

Google Analytics has been announced to become part of the rolling out Google Play Services 4.3, however it is not yet included in the Google Play Services packages list:

http://developer.android.com/reference/gms-packages.html

Any idea when it will become available, and will it be safe to be used straight away, or will it be better to wait for some time to make sure every user has Google Play Services 4.3 already installed?

like image 971
Daniele B Avatar asked Mar 24 '14 13:03

Daniele B


People also ask

How do I know if I have Google Analytics on my Android app?

If this is your first time using a Google services sample, check out the google-services repository. Open Android Studio. Select File > Open, browse to where you cloned the google-services repository, and open google-services/android/analytics .

Why Google Play Services is not supported by my device?

Go To Settings> Security > Device Administators> Disable Android Device manager. Now Go to Apps and Disable Google Play Services and Clear Its data, Clear Data of Play Store too. Reboot device andd Enable Google Play Services.


2 Answers

I've noticed some other differences.

Tracker

To get a new Tracker, use the newTracker() method (accepts both a String value and an int value [for XML configuration]):

googleTracker = gaInstance.getTracker(GA_KEY); // OLD
googleTracker = gaInstance.newTracker(GA_KEY); // NEW

EasyTracker

EasyTracker has now disappeared, so we will have to use GoogleAnalytics.getInstance(this).reportActivityStart(this) as reported by Paito.

Setters

The googleTracker.set() method is no longer available. It has been replaced with more specialised methods, for example:

googleTracker.set(Fields.SCREEN_NAME, null); // OLD
googleTracker.setScreenName(null);           // NEW

Event creation

The googleTracker.send() method has also seen some changes.

googleTracker.send(MapBuilder
                .createEvent(category, action, label, value)
                .build()); // OLD
googleTracker.send(new HitBuilders.EventBuilder()
                .setCategory(category)
                .setAction(action)
                .setLabel(label)
                .setValue(value)
                .build()); // NEW

AppView

It now becomes

googleTracker.send(MapBuilder.createAppView().build());       // OLD
googleTracker.send(new HitBuilders.AppViewBuilder().build()); // NEW

AppViewBuilder

AppViewBuilder has now been deprecated, replaced by the new ScreenViewBuilder class. (thanks Hai Phong for the tip!)


For those who are running into (or have already dealt with) the Dalvik's 64K methods limit, there are now 3K methods that you will be able to get rid of in your application, thanks to this integration.

like image 146
Sebastiano Avatar answered Nov 16 '22 03:11

Sebastiano


It's part of the package list now.

I think the basic functionality works something like this...

import com.google.android.gms.analytics.GoogleAnalytics;

@Override
protected void onStart() {
    super.onStart();
    GoogleAnalytics.getInstance(this).reportActivityStart(this);
}

@Override
protected void onStop() {
    super.onStop();
    GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
like image 36
Paito Avatar answered Nov 16 '22 04:11

Paito