Google Analytics for Android. Users that receive notifications are counted as active

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 13:34:29

问题


I am using Google Analytics in my apps and it works correcly. However, if I have, lets say, 100 active users daily, and then I send a notification, I have a peak of 1000 connected users counted as "active".

I don't know if there is an easy way to prevent these users to count as active. Most of them will not open the notification and I don't want them to count as active. I want to count only the users that open the app, not all who received the notification.

I am using "body" field in the notification that I send, and in the app I create a custom notification.

Is it any way to remove these "active" users?

Thank you very much!


回答1:


Whenever your app receives new Notification, Application OnCreate() method will be invoked.

Not only the Notification, even when you subscribe to system events like ACCESS_WIFI_STATE, ACCESS_NETWORK_STATE, RECEIVE_SMS, RECEIVE_BOOT_COMPLETED.. Application OnCreate() will be invoked.

So inside your Application OnCreate(), don't make any Google Analytics related calls. This will initialize your GA and start the event tracking.

Remove Google Analytics related codes inside your Application OnCreate(), to prevent unwanted event tracking.

Update:

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

getInstance(Context context)
Gets the GoogleAnalytics instance, creating it when necessary.


Multiple way of implementation around this; I recommend you the following way to solve your problem. As document says, prepare the GoogleAnalytics instance, only when it is needed.

Keep the below code inside your Application class, so that your mTracker instance will alive across your application lifecycle.

// Inside Application class
private Tracker mTracker = null;
public synchronized Tracker getDefaultTracker() {
    if (mTracker == null) {
        // Prepare the GoogleAnalytics instance, only when it is needed.
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        mTracker = analytics.newTracker(Config.GA_TRACKING_ID);
        mTracker.enableAutoActivityTracking(true);
        mTracker.enableExceptionReporting(true);
        mTracker.setSessionTimeout(SESSION_TIMEOUT);
    }
    return mTracker;
}

Hope this would help you..



来源:https://stackoverflow.com/questions/44501358/google-analytics-for-android-users-that-receive-notifications-are-counted-as-ac

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