Android: Google Analytics availability in Google Play Services?

好久不见. 提交于 2019-12-03 16:17:10

问题


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?


回答1:


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.




回答2:


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);
}



回答3:


As per conversation in order to use Easytracker replacement with

GoogleAnalytics.getInstance(this).reportActivityStart(this);
GoogleAnalytics.getInstance(this).reportActivityStop(this);

You need to add your config to AndroidManifest like

<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/analytics_global_config" />

I'm still having to get instance of Tracker to send Events, may be somebody else would have better luck at replacing

 EasyTracker.getInstance(mContext).send(MapBuilder....)



回答4:


The documentation for Google Analytics SDK v4 (now part of Google Play Services) has just been published!

https://developers.google.com/analytics/devguides/collection/android/v4/



来源:https://stackoverflow.com/questions/22611295/android-google-analytics-availability-in-google-play-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!