Measuring Events with the TUNE SDK in WebView

Sometimes, your app contains HTML content that you want to measure events on. One approach is to override your WebViewClient and handle the URL loading to find the URL request that corresponds with your event and call the measureEvent method before it loads.

WebView with Android SDK

The following code shows an example for the Android SDK that gets the WebView object “browser” from the layout and overrides the URL load with a check (to see if the URL ends with “skip”). Then it calls a skip action before completing the request. Modify this example to suit your own requests.

WebView browser = (WebView)findViewById(R.id.browser);  
browser.setWebViewClient(new WebViewClient() {  
    @Override  
    public boolean shouldOverrideUrlLoading(WebView view, String url) {  
        if (url.endsWith("skip")) {  
            tune.measureEventName("skip");  
        }  
        return true;  
    }  
});

 

WebView with iOS SDK

The following code shows an example for the iOS SDK that gets the WebView object “browser” from the layout and overrides the URL load with a check (to see if the URL ends with “skip”). Then it calls a skip action before completing the request. Modify this example to suit your own requests.

(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;
    if ([[url lastPathComponent] isEqualToString:@"skip"]) {
        [Tune measureEventName:@"skip"];
    }
    return YES;
}

 

No Comments

Leave a reply