cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Map mobile and web sessions

rdinis
Participant

Hi all,

Im trying to learn the Dynatrace capacities with web and mobile app, so i build something to play 🙂  

  • Web application: easytravel on a vm in linux with oneagent
  • Mobile application: Android with Kotlin with a webview

So, i have this code

 

    // Initializes and configures WebView
    private fun setupWebView() {
        val myWebView: WebView = findViewById(R.id.main_webview)
        Dynatrace.instrumentWebView(myWebView)
        myWebView.settings.javaScriptEnabled = true
        myWebView.loadUrl("http://192.168.0.102:8079") // ez travel on vm


        binding.mainWebview.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
                return false // Ensures URLs open inside WebView, NOT Chrome
            }
        }
    }

 

I have mobile and web sessions, but they are splited, i want to map mobile to web sessions so i follow this documentation

Can I have some lights why Im not able to map sessions?

Thanks,

RD

5 REPLIES 5

matthias_hochri
Dynatrace Pro
Dynatrace Pro

Hey RD,

Usually auto instrumentation would take care for you so you don't need to call instrumentWebView. This call also only adds the JavaScript interface. Still you need to use the Hybrid Monitoring configuration flag. Did you do that? Additionally one thing that you are probably missing is setting the configuration for domains. The Android agent doesn't know that your VM is on 192.168.0.102, so you need to configure this domain in order for the cookies to be set there. 

The cookies (dtAdk) will allow the session merge.

Thanks Matthias for the answer but i could not find the result that i wanted., yet 🤓

Let me explain better what i want to do.
I have a web page that will be access by web view in mobile and browser.
I would like to map the mobile session to the web session.
But this not always happen.

 

Having this in consideration i still need to have the Hybrid Monitoring configuration flag?

This means that i have to add this to code

DynatraceConfigurationBuilder("<YourApplicationID>", "<ProvidedBeaconURL>")
.withHybridMonitoring(true)

https://docs.dynatrace.com/docs/shortlink/oneagent-sdk-for-android#enable-hybrid-application-monitor... 

DynatraceConfigurationBuilder is something that you are using when doing a manual startup. So you are doing manual starting? 

But in general your answer is correct. Additionally as said above you also need to call the builder API for adding domains. 

Ok, lets see the key points:

  • Automatic instrumentation of webviews with oneagent (Web Aplication)
    • Domain equals 192.168.0.102
  • Mobile instrumentation with wizard Android - groovy

My build gradle of the project:

dynatrace {
    configurations {
        sampleConfig {
            autoStart {
                applicationId 'applicationId'
                beaconUrl 'https://beaconUrl.bf.dynatrace.com/mbeacon'
            }
            userOptIn false
            agentBehavior.startupLoadBalancing true
            sessionReplay.enabled false
            exclude.classes "com.dynatrace.sample.android.app.MinimalActivity"
            hybridWebView {
                enabled true
                domains ["192.168.0.102"]
            }
        }
    }
}


Code

    // Initializes and configures WebView
    private fun setupWebView() {
        DynatraceConfigurationBuilder("appID", "https://bc.bf.dynatrace.com/mbeacon")
            .withHybridMonitoring(true)
            .withMonitoredDomains("192.168.0.102")
            .buildConfiguration()
        val myWebView: WebView = findViewById(R.id.main_webview)
        Dynatrace.instrumentWebView(myWebView)
        myWebView.settings.javaScriptEnabled = true
        myWebView.loadUrl("http://192.168.0.102:9200/")


        binding.mainWebview.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
                return false // Ensures URLs open inside WebView, NOT Chrome
            }
        }
    }

 I have tried every combination but it seems that the problem is between the keyboard and the pc 👀

The DynatraceConfigurationBuilder is not needed as you are doing auto instrumentation through the build.gradle configuration anyways. Also the instrumentWebview is usually not needed, but not 100% sure because you are excluding the MinimalActivity.

 

Anyways, please adapt the configuration

hybridWebView {
   enabled true
   domains '192.168.0.102'
}

In general if you want to add more values it is something like this:

hybridWebView {
    enabled true
    domains '192.168.0.102', '...', '...'
}

 

Maybe also add 'debug.agentLogging true' to the configuration so you can see logs.

 

No worries. We are getting there. Thanks for your input.

Featured Posts