Android webview app and Google Analytics

2019-01-26 21:34发布

I have a simple native Android app that is a webview of a website, effectively to make the mobile-ready site native-like if you will. The website already has Google Analytics installed.

What might be a good way to track which visitors are using the app?

  • I could adding Android Native App Tracking, but I presume that would double track the users. Unless it's smart enough to connect the visits?
  • I could pass custom get variable to the site that maybe adds a custom attribute to the tracking for native app users. But that doesn't sound very clean.

What might be best for tracking? I feel there's got to be an obvious answer I'm missing.

1条回答
太酷不给撩
2楼-- · 2019-01-26 22:08

that should help you:

Now getting back to the Analytics tracking of this web app, I used the code provided by Google here. So the code becomes somewhat like this.

public class  myWebApp  extends Activity{

      Webview mWebview;
      GoogleAnalyticsTracker tracker;

  protected void onCreate(Bundle savedInstanceState) {

        tracker = GoogleAnalyticsTracker.getInstance();

        // Start the tracker in manual dispatch mode. The following UA-xxxxxxx-x code must be replaced by //your web property ID.

       tracker.startNewSession("UA-xxxxxxx-x", this);

       mWebview = new WebView(this);
       mWebview .setWebViewClient(new myWebViewClient());
       mWebview .loadUrl("file:///android_asset/www/index.html"); 




    private class myWebViewClient extends WebViewClient
    {

        //After the user visits a particular page, send the tracking notification to GoogleAnalytics.
         @Override
         public void onPageStarted(WebView view, String url, Bitmap favicon)
         {
tracker.trackPageView( mWebview.getUrl());
tracker.dispatch();
         }
      }

   }

http://www.the4thdimension.net/2011/11/using-google-analytics-with-html5-or.html

And in stats of google analytics you should get some info at least about operating system android.

查看更多
登录 后发表回答