Using Google Analytics for Android Widget

I want to use Google Analytics for the first time.

I have a simple widget and when I click on it a simple action opens. Not that hard. I put the following code in the onCreate method of my activity:

public static GoogleAnalytics analytics;
public static Tracker tracker;


... from here in onCreate

if(analytics == null || tracker == null){
            analytics = GoogleAnalytics.getInstance(this);
            analytics.setLocalDispatchPeriod(1800);

            tracker = analytics.newTracker("UA-11111111-1");
            tracker.enableExceptionReporting(true);
            tracker.enableAdvertisingIdCollection(true);
            tracker.enableAutoActivityTracking(true);
        }

      

Do I need to put the same code in my AppWidgetProvider onUpdate method or is that enough? An on-screen widget is considered an active user in Google Analytics, and if so, does Google Analytics make 2 active users if they have an on-screen widget and open the app, or is Google smart enough to know that both (widget and app) are on one device?

+3


source to share





All Articles