segmentio / analytics-android

The hassle-free way to add analytics to your Android app.
https://segment.com/docs/sources/mobile/android/
MIT License
377 stars 216 forks source link

context.device.advertisingId Not Being Collected #780

Open tcrawford94 opened 2 years ago

tcrawford94 commented 2 years ago

Our Analytics track & screen calls are not being sent with a context.device.advertisingId. We have minifyEnabled set to true in our build.gradle, and disabling this fixes the issue, but that isn't an acceptable solution here.

Adding the following proguard rules to our project fixes the issue while minifying:

-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient { *; }
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info { *; }

Segment SDK is only a sustainable service and library for us to use if we can assume it will continue to work between library version updates. For these reason, we would also request that you package any other necessary proguard rules in the analytics-android library itself, as opposed to instructing us to keep our proguard rules up to date based on your latest documentation:

-keep class com.segment.analytics.** { *; }
-keep class androidx.lifecycle.DefaultLifecycleObserver

Other fixes attempted: There's a small amount of documentation highlighting the requirement of including "Google Play Services Ads Library" to our project, but that does not fix the issue. Additionally, I'm confused why anything more than the Google Play Services Ads Identifier library would be necessary, as Ads Library requires us to sign up for Ad Mob like we plan to display ads in our app. I believe the documentation should clarify what is required here. I believe all that would be needed is the following line in the build.gradle, even though this didn't fix the issue.

implementation 'com.google.android.gms:play-services-ads-identifier:18.0.0'
tcrawford94 commented 2 years ago

Edited issue, adding more comments. Please let me know if I can provide any more details here.

jflavio11 commented 2 years ago

@tcrawford94 This got me confused too. The lib documentation mentions that we should add the Google Ads Library as a dependency in order to let the Segment lib collect the Advertising ID.

Moreover, if your app targets SDK 33 or later, Google Play Store Console shows a warning mentioning that we must declare the Advertising ID permission in the Android Manifest (which is included by default by the Google Ads Library). What I do not understand is: Will the Segment Library work or not if we don't include the Google Ads Library as a dependency in our apps?

carlosmonzon commented 2 years ago

@tcrawford94 @jflavio11 I have exactly the same scenario. I have not added the Advertising ID permission in the Android Manifest and I am targeting android 13 now.

Should we declare that our app uses Advertising ID because of segment?

mrtnrst commented 2 years ago

Ideally, Segment updates their SDK to include the requirement in the manifest so it will be merged into users' apps when they update the version number.

I can also open a PR for this if no one has started yet.

sterlingudell-th2 commented 2 years ago

I'd like to strongly second @tcrawford94's request that the AdvertisingIdClient ProGuard rules be added to the docs, as collecting the advertising ID won't work without them. If there's a way to include these in the actual library itself, that'd be even better.

Also, @mrtnrst's suggestion of adding the following line to the library's manifest only makes sense:

    <uses-permission android:name="com.google.android.gms.permission.AD_ID" />