简体   繁体   中英

Android Google Analytics v2 Broadcast Receiver for all SDKs

I started implementing the Google Play Campaign as found here:

https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#google-play-tracking

the i hit this line

https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#known-issues

which states:

Only one BroadcastReceiver class can be specified per app. Should you need to incorporate two or more BroadcastReceivers from different SDKs, you will need to create your own BroadcastReceiver class that will receive all broadcasts and call the appropriate BroadcastReceivers for each type of broadcast.

i mean doesn't the com.google.analytics.tracking.android.AnalyticsReceiver works for all SDKs? I need for SDK 10(2.3.3) and above! Is is enough? And if not what do i need and how do i make it?

That is referring to multiple analytics providers, all of which may need to handle the install event. In work I've done, I've defined a custom BroadcastReceiver that passes the intent to Google Analytics, an internal analytics system, and MobileAppTracking. Situations like this are fairly common.

The "SDK" you are talking about is more properly called API Levels, the iterations on the Android API.

So the case Google is referring to is like this:

public class InstallReceiver extends BroadcastReceiver {
        public static final String TAG = InstallReceiver.class.getCanonicalName();

        @Override
        public void onReceive(Context context, Intent intent) {

            // Google Analytics
            new CampaignTrackingReceiver().onReceive(context, intent);

            // HasOffers
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
                Tracker hasOffersTracker = new Tracker();
                hasOffersTracker.onReceive(context, intent);
            }

            Log.d(TAG, intent.getExtras().getString("referrer");
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM