Android webview应用和Google Analytics

时间:2021-11-01 15:16:08

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.

我有一个简单的原生Android应用程序,它是一个网站的webview,有效地使移动就绪网站本地化,如果你愿意。该网站已安装Google Analytics。

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?
  • 我可以添加Android Native App Tracking,但我认为这会加倍跟踪用户。除非它足够聪明地连接访问?

  • 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.
  • 我可以将自定义get变量传递给站点,该站点可能会为本机应用用户的跟踪添加自定义属性。但这听起来不是很干净。

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

什么可能最适合跟踪?我觉得我必须找到一个明显的答案。

1 个解决方案

#1


2  

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.

现在回到此网络应用的Google Analytics跟踪,我在这里使用了Google提供的代码。所以代码变得有点像这样。

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.

在谷歌分析的统计数据中,你应该至少获得一些关于操作系统android的信息。

#1


2  

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.

现在回到此网络应用的Google Analytics跟踪,我在这里使用了Google提供的代码。所以代码变得有点像这样。

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.

在谷歌分析的统计数据中,你应该至少获得一些关于操作系统android的信息。