GoogleChrome / android-browser-helper

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library.
Apache License 2.0
687 stars 288 forks source link

In Firebase User Engagement Events: most of rendered Class screens are WebViewFallbackActivities #244

Closed enricofacchinetti closed 3 years ago

enricofacchinetti commented 3 years ago

Hi, I don't know if it is just a bug, but there is something not properly expected in the following implementation of my TWA activity.

I have not a simple TWA Activity declared in AndroidManifest.xml. I implemented some adding code, extending your LauncherActivity class to achieve my purposes.

Here the details: In my LAUNCHER AppCompatActivity named CustomTwaActivity, I start a new Activity called CustomQueryStringLauncherActivity extending LauncherActivity in which I manipulate the app's default launching url. The matter is that, as shown in my Firebase User Engagement Events' section, only 33% of rendered screen classes are of type CustomQueryStringLauncherActivity while the 66% of the rendered classes are WebViewFallbackActivity. As a result only 33% of my app's rendered classes are LauncherActivity and this is a problem because my code is not run most of the times and because of the known problems related to WebViewFallbackActivity.

Is this normal? 33% of the rendered class of type LauncherActivity is not an anomaly?

Here is my code:

public class CustomTwaActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           Context context = getApplicationContext();
           Intent launcherIntent = new Intent(CustomTwaActivity.this, CustomQueryStringLauncherActivity.class);
           startActivity(launcherIntent);
           finish();
}

public class CustomQueryStringLauncherActivity extends LauncherActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    @Override
    protected Uri getLaunchingUrl() {
        Uri uri = super.getLaunchingUrl();  
        Uri returnUri = uri
                    .buildUpon()
                    .appendQueryParameter(key_1, value_1)
                    .appendQueryParameter(key_2, value_2)
                    .build();
        return returnUri ;
    }
}
  <activity android:name="com.coelotec.meteodrome.CustomTwaActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.coelotec.meteodrome.CustomQueryStringLauncherActivity"
                  android:label="@string/app_name">

            <meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="https://app.my_own_url.it" /> 

            <meta-data android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
                android:value="@string/provider_authority"/>

            <meta-data android:name="android.support.customtabs.trusted.FALLBACK_STRATEGY"
                android:value="webview" />

            <intent-filter android:autoVerify="true"
                tools:targetApi="m">
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="https"
                    android:host="app.my_own_url.it"/>
            </intent-filter>

        </activity>

        <activity android:name="com.google.androidbrowserhelper.trusted.WebViewFallbackActivity"
            android:configChanges="orientation|screenSize" />

User Engagement WebViewFallBackctivity

PEConn commented 3 years ago

Hey, so looking at your code:

As for the firebase user engagement events, we'll need to look into it a bit more, but I've got a theory:

So I suspect there's nothing much going wrong - most users are seeing the TWA in the browser, it's just that Firebase isn't recording it.

We could test this by looking at your server logs. If you launch the TWA with a specific URL (eg, www.mysite.com/?twa=true) you can then see what % of people visiting that URL are in a WebView (more info here).

andreban commented 3 years ago

+1 to Peter's view on engagement levels. Something like the change on #237 would ensure the Trusted Web Activity is only started after Firebase is initialised.

andreban commented 3 years ago

Closing, as things seems to be working as intended.

enricofacchinetti commented 3 years ago

@PEConn Thanks for your reply and sorry for delay in my reply.

I'm not sure what the point of CustomTwaActivity is - it looks like it just launches CustomQueryStringLauncherActivity. Could you not just set that to be launched directly?

As from your advise I removed CustomQueryStringLauncherActivity and kept CustomTwaActivity.
More details on how CustomTwaActivity works are in a new separated thread I recently opened for a different matter (https://github.com/GoogleChrome/android-browser-helper/issues/281). I had seen this "two separated activities approach" in a stackoverflow.com thread. I thought there was some reason I didn't know to do so. Actually it was simply useless.

As far as your interesting theory concerning the reason why so many WebViewFallbackActivity are recorded, your explanation seems to be supported by the fact that in "https://play.google.com/" there is a similar metric (even better I would say that it's the same metric). And in this metric the percentage of CustomQueryStringLauncherActivity is 85% while WebViewFallbackActivity is 15% out of all cases. The only problem is that now I'm not able to find it again. To be honest play.google.com interface could be more user friendly, but I'm sure that the values was those one. Thanks. E.F.