xamarin / GooglePlayServicesComponents

Other
316 stars 147 forks source link

Google Tag Manager (via Firebase) Not Loading #260

Open henduck opened 5 years ago

henduck commented 5 years ago

The official recommendation for Google Tag Manager says to use Firebase Analytics as the data layer for GTM tags: https://developers.google.com/tag-manager/android/v5/

I have followed their instructions as best as possible, (substituting the appropriate Xamarin nuget packages for their native equivalents). While my events are showing up in Firebase just fine, there seems to be some issue with GTM. Since it appears the initialization of GTM happens without any explicit code, all I have to go by are the logs printed out on startup, and this line in particular seems to possibly indicate the problem:

[FA] Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)

I have the equivalent setup on iOS working just fine, and events there show up both in Firebase and GoogleAnalytics via GTM.

Xamarin.Android Version: 9.4.0.51 (VS for Mac) MacOS 10.14.3 Xamarin.GooglePlayServices.TagManager - v71.1604.0 All other GooglePlayServices nugets: 71. All Firebase nugets: 71.

If it's any help, here are all the FirebaseAnalytics logs being printed (with all other console output removed, obviously):

[FA] Registered activity lifecycle callback
[FA] Collection enabled
[FA] App package, google app id: com.test.mobile, <id redacted>
[FA] App measurement is starting up, version: 14711
[FA] To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
[FA] Faster debug mode event logging enabled. To disable, run:
[FA]   adb shell setprop debug.firebase.analytics.app .none.
[FA] Debug-level message logging enabled
[FA] Connecting to remote service
[FA] Connection attempt already in progress
[FA] onActivityCreated
[FA] Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)
[FA] Logging event (FE): ScreenViewed_Testing, Bundle[{testkey=testval, firebase_event_origin(_o)=app}]
[FA] Connection attempt already in progress
[FA] Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=274168793780978625}]
[FA] Connection attempt already in progress
[FA] Connection attempt already in progress
[FA] Activity resumed, time: 106785828
[FA] Connected to remote service
[FA] Processing queued up service tasks: 5
[FA] Logging event (FE): ScreenViewed_AnotherTest, Bundle[{testkey=testval, firebase_event_origin(_o)=app, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=274168793780978625}]
[FA] Inactivity, disconnecting from the service
henduck commented 5 years ago

GTMTest.zip Sample project illustrating this issue (only Android project has been implemented here, and GTM container json and google-services.json files have been cleared out)

moljac commented 5 years ago

@henduck Thanks for the repro sample.

Checking it.

henduck commented 5 years ago

Worth noting: TagManager seems to work when all GooglePlayServices are rolled back to v60. (unfortunately, that is not a workable option for us, due to other dependencies)

alext-avi commented 5 years ago

Is there any movement or remediation steps on this? Experiencing the same.

savior1980 commented 5 years ago

We have exactly the same issue here. Is there any workaround?

WSudolPGS commented 4 years ago

Hi any news? this is critical....

moljac commented 4 years ago

@henduck I see you are using GPS Tagmanager and Firebase Analytics?

Can you try Xamarin.Android.ManifestMerger, because it smells like manifest is not properly merged.

@WSudolPGS @savior1980 @alext-avi Can you provide info if you are using more than just Tagmanager?

EDIT: ManifestMerger is a nuget package that adds MSBuild tasks that properly merge AndroidManifes.xml from various nuget packages for bound artifacts.

https://www.nuget.org/packages/Xamarin.Android.ManifestMerger/1.0.0-preview03

WSudolPGS commented 4 years ago

@moljac we using all sort of GoogleService Packages like maps or firebase, merger helps for getting rid of "Failed to retrive Firebase Instance Id" but still we get "[FA] Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)"

We created empty project just with TagManager and it initialize perfect on v60 and failes on v71

moljac commented 4 years ago

@WSudolPGS Can you open new issue please?

"[FA] Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)"

This is bindings error.

We created empty project just with TagManager and it initialize perfect on v60 and failes on v71

Can you provide link to the repro sample, please?

WSudolPGS commented 4 years ago

You already have sample solution, @moljac GTMTest.zip which @henduck uploaded few comments above is exactly what happens, i run VS 2019 16.3.6.

Adding ManifestMerger to GTMTest only helps with: E/FA ( 5507): Missing google_app_id. Firebase Analytics disabled but main problem still exists

pgs-mszpunar commented 4 years ago

I get the same error:

[FA] Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)

It can be easily reproduced in GTMTest.zip uploaded by @henduck. ManifestMerger does not help and the error still exists. Also, confirm that downgrade Xamarin.GooglePlayServices.TagManager from v70 to v60 solves the issue. It seems to be only v70 problem.

WSudolPGS commented 4 years ago

Speed of investigation is outstanding

Thier-WAY commented 4 years ago

We are facing the same error: [FA] Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97).

Downgrading to v60 is not an option in our case because other dependencies require v71.

KoenDeleij commented 4 years ago

Same issue here. Firebase analytics seems to initialize fine, but when the latest TagManager package is added as dependency, Analytics tries to load TagManager and fails.

MihaMarkic commented 4 years ago

Same here.

antoniokly commented 4 years ago

[FA] Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)

same problem here, any updates?

Gunner92 commented 4 years ago

Same Problem Any Updates ?

JoacimWall commented 4 years ago

any update we also get Failed to invoke Tag Manager's initialize

danieljgmaclean commented 4 years ago

@moljac Do you have plans on resolving this issue? (I ask because it's been open for so long) Sadly, also facing this issue, and it seems our only workaround is a downgrade.

Thier-WAY commented 4 years ago

@moljac When can we expect an update on this issue? Six months have passed after my last post without any news about a solution on this.

aian23 commented 4 years ago

Any updates on this?

moljac commented 4 years ago

Something crossed my mind this morning and we just discussed it...

Could you try adding Proguard rule to your app (either to existing file or add new file i.e. proguard.cfg) and add this line:

-keep class com.google.android.gms.measurement.internal.**  { *; }

This will make app bigger, but not sure how much bigger. If you can provide updated sample I might go and with trial/error keep only classes and methods needed for minimal functionality. Otherwise I will not have time to play with the samples from scratch.

aian23 commented 4 years ago

@moljac - tried this our earlier, but GTM still isn't working. Here are the logs that I saw:

image image

As seen in the logs, it looks like the JSON container still aren't being pulled.

Were you able to check on this?

aian23 commented 4 years ago

@moljac - was wondering if you want to reconsider checking the v60 versions since the GTM is working in Android in this version, although it only works erratically. At least it's already working and we may just need to check why it works erratically. Maybe you can also find clues in that version and why it works somewhat in that and not in the higher versions? We really need a fix for this as GTM works erratically in Android while using v60. The v71 versions on the other hand don't work at all.

Hoping to hear your thoughts

aian23 commented 4 years ago

@moljac - Good day! Would just like to ask if you have any ideas with the cause of the issue or if you want to consider the suggestion above. We just really need the fix right now as this is very urgent. Hoping you could take a look into this once again.

katariyaprakash7 commented 3 years ago

Hey there,

I have put everything correctly (google service.json and GTM-TEST123.json file) and still getting the container not found.

I have added the firebase google-service.json file and its working fine for me but now I am trying for the GTM SDK integration i got the following error.

Does anyone face this please provide your thought here to your little brothers.

Find the screenshot below : image image

Thanks in advance.

katariyaprakash7 commented 3 years ago

@moljac Need help here !!

moljac commented 3 years ago

@GoldenGlitterBug Thanks for the feedback.

@moljac I am having the same issue. This issue exists since 2019. Any solution/updates on this?

I am aware of that.

Java.Lang.NoSuchMethodError: 'No virtual method transactAndReadExceptionReturnVoid(ILandroid/os/Parcel;)V in class Lcom/google/android/gms/internal/measurement/zzq; or its super classes (declaration of 'com.google.android.gms.internal.measurement.zzq' appears in /data/app/com.xxpackage.xxname-OT45U1GpA6ulFZw56hg9XQ==/base.apk)'

Well I'll need to dive deeper into that, but I have no time, so this will remain very low priority, due to the fact packages are 71.*, so close to unsuporrted.

Using following Nuget Packages:

Xamarin.Firebase.Analytics 71.1630.4 Xamarin.Firebase.Analytics.Impl 71.1630.4 Xamarin.Firebase.Messaging 121.0.1 Xamarin.GooglePlayServices.TagManager 71.1604.4 Xamarin.GooglePlayServices.TagManager.Api 71.1604.4

Old packages. Current versions are prefixed with 1, so 1xy.*

Any insight into this issue would be super helpful, as my search hasn't turned up anything useful that is Xamarin-related so far.

It doesn't have to be Xamarin related, though smells like some code uses method transactAndReadExceptionReturnVoid in class Lcom/google/android/gms/internal/measurement/zzq. This class might have be removed by us, because it is obfuscated and not normally intended to be used from C#, or optimizer removed it (R8 orproguard). Try adding R8 (progguard rules for that class/method). This is your best shot for now.

moljac commented 3 years ago

@moljac I am having the same issue. This issue exists since 2019. Any solution/updates on this? I am developing Mobile app using Xamarin Android. I have integrated Firebase with our app successfully. I am using GTM android version 5. https://developers.google.com/tag-manager/android/v5 Google Tag Manager container with test tag (GTM-xxxxxxx.json) is placed in Assets/Containers folder as specified, however while all event records ARE showing up in Firebase Analytics console, they do not seem to be sent to GTM. Logs seem to indicate an issue with loading GTM:

Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)
and when run container preview:
Java.Lang.NoSuchMethodError: 'No virtual method transactAndReadExceptionReturnVoid(ILandroid/os/Parcel;)V in class Lcom/google/android/gms/internal/measurement/zzq; or its super classes (declaration of 'com.google.android.gms.internal.measurement.zzq' appears in /data/app/com.xxpackage.xxname-OT45U1GpA6ulFZw56hg9XQ==/base.apk)'

Using following Nuget Packages: Xamarin.Firebase.Analytics 71.1630.4 Xamarin.Firebase.Analytics.Impl 71.1630.4 Xamarin.Firebase.Messaging 121.0.1 Xamarin.GooglePlayServices.TagManager 71.1604.4 Xamarin.GooglePlayServices.TagManager.Api 71.1604.4 Android min sdk version is 24 and target sdk version is 30. Any insight into this issue would be super helpful, as my search hasn't turned up anything useful that is Xamarin-related so far.

Hey there i have a solution for this!!!

You can write your query in detail on katariyaprakash7@gmail.com i will help you out there.

It would be nice to provide solution in public (some sort of blog or repro sample/repo), so everyone would benefit from it.

Thanks

katariyaprakash7 commented 3 years ago

@moljac I am having the same issue. This issue exists since 2019. Any solution/updates on this? I am developing Mobile app using Xamarin Android. I have integrated Firebase with our app successfully. I am using GTM android version 5. https://developers.google.com/tag-manager/android/v5 Google Tag Manager container with test tag (GTM-xxxxxxx.json) is placed in Assets/Containers folder as specified, however while all event records ARE showing up in Firebase Analytics console, they do not seem to be sent to GTM. Logs seem to indicate an issue with loading GTM:

Failed to invoke Tag Manager's initialize() method: java.lang.reflect.InvocationTargetException: com.google.android.gms.measurement.internal.zzda.zza(Unknown Source:97)
and when run container preview:
Java.Lang.NoSuchMethodError: 'No virtual method transactAndReadExceptionReturnVoid(ILandroid/os/Parcel;)V in class Lcom/google/android/gms/internal/measurement/zzq; or its super classes (declaration of 'com.google.android.gms.internal.measurement.zzq' appears in /data/app/com.xxpackage.xxname-OT45U1GpA6ulFZw56hg9XQ==/base.apk)'

Using following Nuget Packages: Xamarin.Firebase.Analytics 71.1630.4 Xamarin.Firebase.Analytics.Impl 71.1630.4 Xamarin.Firebase.Messaging 121.0.1 Xamarin.GooglePlayServices.TagManager 71.1604.4 Xamarin.GooglePlayServices.TagManager.Api 71.1604.4 Android min sdk version is 24 and target sdk version is 30. Any insight into this issue would be super helpful, as my search hasn't turned up anything useful that is Xamarin-related so far.

Hey there i have a solution for this!!! You can write your query in detail on katariyaprakash7@gmail.com i will help you out there.

It would be nice to provide solution in public (some sort of blog or repro sample/repo), so everyone would benefit from it.

Thanks

Hi @moljac,

I just need to know the exact details to understand the exact issue and that's why I asked to reach out. Because the detail here is improper.

There is no other intention to communicate it via mail my friend.

wcoder commented 3 years ago

Seems like a working solution: https://github.com/xamarin/GooglePlayServicesComponents/issues/358#issuecomment-922415414