quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

Manual tracking does not work when using Intents.

Open pkhivesara opened this issue 5 years ago • 7 comments

Step 1: Describe your environment

  • Android device: Pixel 3
  • Android OS version: Android 9
  • Google Play Services version:
  • Firebase/Play Services SDK version: 17.2.0

Step 2: Describe the problem:

While using the setCurrentScreen method to manually track user engagements, the screen_name is omitted when using Intent to move from one activity to another.

However, if a FragmentTransaction is executed, the screen_name tag is logged successfully.

Observed Results:

  • The screen_name tag is not logged when using an Intent. However it works as expected when using FragmentTransaction.

Expected Results:

  • The setCurrentScreen should log the screen_name as expected for both scenarios.

pkhivesara avatar Sep 26 '19 06:09 pkhivesara

Anyone would be able to assist me on this? Is this a known firebase issue?

pkhivesara avatar Oct 03 '19 11:10 pkhivesara

@pkhivesara thanks for filing this, sorry about my very slow response. Could you show the piece of code that's not working as expected?

Also could you try using this method to gather logs of what's being sent? https://firebase.google.com/docs/analytics/events?platform=android#view_events_in_the_android_studio_debug_log

samtstern avatar Oct 03 '19 12:10 samtstern

@samtstern I will upload a sample repo in a bit

pkhivesara avatar Oct 03 '19 12:10 pkhivesara

@samtstern Please find the sample code: https://gitlab.com/pkhivesara/firebasetest

Attached along are two screenshots, using fragment and activity approach both of which fail to register the firebase_screen/ga_screen attribute.

activity-approach fragment-approach

Maybe I have misunderstood as to manual tracking is supposed to be used?

pkhivesara avatar Oct 03 '19 12:10 pkhivesara

This looks like it might be the same issue as https://github.com/firebase/quickstart-android/issues/935

So are you saying this is the line that doesn't work? https://gitlab.com/pkhivesara/firebasetest/blob/master/app/src/main/java/com/test/firebaseandroidsample/SecondActivity.java#L18

samtstern avatar Oct 03 '19 12:10 samtstern

The screen_class is being registered however firebase_screen/ga_screen always shows as NOT SET (as we can see in the screenshot). Any ideas on how to set the firebase_screen attribute. This is a major bug as far as tracking is concerned.

pkhivesara avatar Oct 03 '19 13:10 pkhivesara

The app appears to be calling setCurrentScreen() from onCreate() in its activity, fragment, etc. This is not where you'd want to call setCurrentScreen() as onCreate() is for logic that gets called once during the app's lifetime. Instead it should be called from onResume().

We do automatic screen tracking based on activity lifecycles but not fragment lifecycles. So, regardless of whether setCurrentScreen() were called on an activity resume we would log a screen_view event. However, automatic screen tracking does not set a screen name.

So in the absence of any manual calls to setCurrentScreen() I'd expect to see the events you're seeing when the activity is shown. I'm not sure why you're getting the desired results with FragmentTransaction.

In any case you'll probably get much better results just moving your calls to setCurrentScreen() from onCreate() to onResume().

dmorenus avatar Oct 07 '19 22:10 dmorenus