简体   繁体   中英

How to track webview content with Google Analytics in android?

I have a webview in my app and set its content like the following:

mWebView.loadUrl("http://.......");

I get my Google Analytics Tracker like the following:

public synchronized Tracker getTracker(TrackerName trackerId) {
        if (!mTrackers.containsKey(trackerId)) {

            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics
                    .newTracker(R.xml.app_tracker)
                    : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics
                            .newTracker(PROPERTY_ID) : analytics
                            .newTracker(R.xml.ecommerce_tracker);
            mTrackers.put(trackerId, t);

        }
        return mTrackers.get(trackerId);
}

My question is, How can i use this tracker to track the urls loaded in my webview?

Thanks

Just extend onPageFinished method

mWebView.setWebViewClient(new WebViewClient() {

    public void onPageFinished(WebView view, String url) {

    // String url is what you are looking for
    // Do the analytics stuff here

    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM