Tealium/tealium-kotlin

TagManagement dispatcher kills app's WebView performance

Closed this issue · 6 comments

Adding TagManagement dispatcher to Tealium decimates the performance of WebView which is displayed on the home screen of our app. Home page instead of loading in 2 to 5 seconds, loads in 30 to 90 seconds. This happens only on the cold boot and fresh installation. After loading it fully at least once, the second loading happens without any additional delays. Removing TagManagement module from the app solves the issues entirely. It doesn't matter what page or payload is loaded, our custom HTML, google.com etc.

Because such a long load is unusable from the UX perspective, the only workaround we have for now is blocking creation of the TagManagement dispatcher object and suspending any calls to this dispatcher until the home page is loaded, which is not a great solution and brings many other challenges.

Here's the comparison in the logs:
Loading with TagManagement, takes 35 seconds

2024-11-04 18:21:38.071   TealiumTest             com.example       D  [T#main] | Starting to load https://www.google.com
2024-11-04 18:22:13.794   WebViewLoader           com.example       D  [T#main] | Received http error with https://tags.tiqcdn.com/favicon.ico: 404: Not Found
2024-11-04 18:22:14.597   TealiumTest             com.example       D  [T#main] | onPageFinished https://www.google.com

Loading without TagManagement, takes 5 seconds

2024-11-04 18:27:25.991  TealiumTest             com.example       D  [T#main] | Starting to load https://www.google.com
2024-11-04 18:27:30.371  TealiumTest             com.example       D  [T#main] | onPageFinished https://www.google.com

It doesn't matter if the home page is shown after a considerable amount of time in the user journey. Users first go through onboarding, so there's a significant delay before showing the home page for the first time. The issue of long WebView loading happens at least once for each user.

Any help or recommendations on how to resolve this greatly appreciated

@tomczyn Thanks for sharing this. We'll review and hopefully be able to make some suggestions to alleviate the issue.

@tomczyn I've been unable to reproduce this locally with a sample app so far - loading a webview into an activity on startup as well as loading the TagManagement dispatcher too. There are two things I would mention based on the information provided though:

  • There appears to be two 404's on the favicon.ico - are you creating multiple Tealium instances?
  • The length of delay feels long enough to be being caused by a timeout, are you customising the TagManagement URL at all?

Since you sound like you're able to reproduce it consistently, could I suggest raising a support ticket so we can go through the scenario directly with you? perhaps with a minimal reproducible example.

Thank you for the response, @jameskeith, as for the answer

  • That was a Logger misconfiguration, it logged the same message twice, sorry for the confusion, the object is initialized once
  • No customisation to the TagManagement URL. I've copied the implementation locally to be able to debug it better

After digging more into a WebViewLoader class it seems that the delay is caused by TagManagement webView.loadUrl(utag_url) call which for some reason takes more than 30 seconds to load which is the same amount the app's WebView is delayed. After putting more logs into the dispatcher implementation, it seems to confirm that scenario. Here are the logs, TealiumTest relates to internal implementation of TagManagement object:

2024-11-05 14:25:37.685    TealiumTest    Creating tealium
2024-11-05 14:25:37.738    TealiumTest    WebViewLoader init
2024-11-05 14:25:37.738    TealiumTest    initializeWebView
2024-11-05 14:25:37.739    TealiumTest    hasReachedMaxErrors false
2024-11-05 14:25:37.875    TealiumTest    fetchQueryParams
2024-11-05 14:25:37.880    TealiumTest    loadUrlToWebView
2024-11-05 14:25:37.880    TealiumTest    decorateUrlParams
2024-11-05 14:25:37.881    TealiumTest    enableCookieManager
2024-11-05 14:25:37.898    TealiumTest    web.loadUrl(url) https://tags.tiqcdn.com/utag/company/dev/mobile.html        # Starting Tealium internal WebView load
2024-11-05 14:25:37.909    TealiumTest    shouldInterceptRequest https://tags.tiqcdn.com/utag/company/dev/mobile.html
2024-11-05 14:25:37.909    TealiumTest    isFavicon
2024-11-05 14:25:37.913    TealiumTest    onProgressChanged 10
2024-11-05 14:25:37.915    TealiumTest    onLoadResource
2024-11-05 14:25:37.915    TealiumTest    Loaded resource: https://tags.tiqcdn.com/utag/company/dev/mobile.html
2024-11-05 14:25:38.491    TealiumTest    onPageStarted
2024-11-05 14:25:38.494    TealiumTest    onProgressChanged 70
2024-11-05 14:25:38.504    TealiumTest    shouldInterceptRequest https://tags.tiqcdn.com/utag/company/dev/utag.js
2024-11-05 14:25:38.505    TealiumTest    isFavicon
2024-11-05 14:25:38.505    TealiumTest    onLoadResource
2024-11-05 14:25:38.505    TealiumTest    Loaded resource: https://tags.tiqcdn.com/utag/company/dev/utag.js
2024-11-05 14:25:38.672    TealiumTest    onProgressChanged 70
2024-11-05 14:25:39.074    App            Starting to load https://www.google.com         # Starting app WebView load
2024-11-05 14:26:20.440    TealiumTest    onProgressChanged 80
2024-11-05 14:26:20.442    TealiumTest    onProgressChanged 100
2024-11-05 14:26:20.443    TealiumTest    onProgressChanged 100
2024-11-05 14:26:20.444    TealiumTest    onPageFinished        # Finished Tealium internal webView.loadUrl(utag_url) call, 43 seconds
2024-11-05 14:26:20.445    TealiumTest    registerNewSessionIfNeeded
2024-11-05 14:26:20.453    TealiumTest    shouldQueue
2024-11-05 14:26:20.454    TealiumTest    hasReachedMaxErrors false
2024-11-05 14:26:20.610    TealiumTest    shouldInterceptRequest https://tags.tiqcdn.com/favicon.ico
2024-11-05 14:26:20.610    TealiumTest    isFavicon
2024-11-05 14:26:20.613    TealiumTest    onReceivedError
2024-11-05 14:26:20.614    TealiumTest    onReceivedError other
2024-11-05 14:26:20.615    TealiumTest    isFavicon
2024-11-05 14:26:20.617    TealiumTest    onReceivedHttpError
2024-11-05 14:26:20.618    TealiumTest    Received http error with https://tags.tiqcdn.com/favicon.ico: 404: Not Found
2024-11-05 14:26:21.508    App            onPageFinished https://www.google.com         # Finished app WebView load, 42 seconds

App's WebView finished the loading only after Tealium internal WebView has called onPageFinished. It appears that the issue is not related to the Kotlin code per se, but rather to the event of loading the utag URL and how that affects Main thread and other instances of WebView's throughout the app.

Thank you for the suggestion of raising the support ticket, that might be the way to go with this issue.

Small update after few more tests is that even after opening the Home Page after the internal Tealium WebView has finished loading, the dispatcher still significantly slows down loading of the Home Page, so it seems it's not only related to the loadUrl and confirms the scenario that the Home Page can be shown at any later point in time and the dispatcher still interferes with the app WebView

@tomczyn Thanks for the additional information and for taking the time to step so far through the issue yourself.
It very much looks like the two webviews are not interacting well to both being loaded at the same time - I can't say with any confidence why it would take so long to load our one, the Mobile.html file it loads is generally tiny, and our CDNs are not known for being slow, so perhaps there's something account / profile specific that's causing the drag.

With regards to the load order, we obviously have no choice but to load it on the main thread, and we try to get initialized as soon as possible to make tracking available as soon as possible. But in this scenario perhaps there's a case for the TagManagement Dispatcher to support a customisable delay to the WebView initialization - it's not ideal as it means we'd need to wait longer before processing events, but perhaps it would allow for resolving this issue.

With all that said, it would still be great if we could get a minimal reproducible example which we may be able to do with some more details on your app, so that we can try and resolve it with some level of confidence. So i'd still suggest we get a support ticket opened to try and get that progressing if possible.

The issue was in the profile configuration, so it's not an SDK implementation fault. Thank you for the investigation :)