Android的应用程序的WebView和谷歌Analytics(分析) [英] Android webview app and Google Analytics
问题描述
我有一个简单的原生Android应用程序是一个网站的网页视图,有效地使移动准备现场母语一样,如果你会的。该网站已经安装谷歌Analytics(分析)。
什么是可以跟踪哪些访问者使用的应用程序的好办法?
- 我可以加入 Android原生应用程序跟踪,但我presume那会
双轨用户。除非它是足够聪明的访问连接? - 我能通过定制得到变量,也许增加了一个定制网站
属性给本机应用程序的用户跟踪。但是,这并不
声音很干净。
什么可能跟踪是最好的吗?我觉得我们有了是一个明显的答案我错过了。
这应该可以帮助您:
现在又回到了这个Web应用程序的分析跟踪,我使用由谷歌这里提供的code。
因此,code变得有些像这样的。
块引用>公共类myWebApp延伸活动{ 的WebView mWebview;
GoogleAnalyticsTracker跟踪; 保护无效的onCreate(捆绑savedInstanceState){ 跟踪= GoogleAnalyticsTracker.getInstance(); //开始在手动模式下派遣跟踪。下面UA-XXXXXXX-X code必须由//你的网站资源编号代替。 tracker.startNewSession(UA-XXXXXXX-X,这一点); mWebview =新的WebView(本);
mWebview .setWebViewClient(新myWebViewClient());
mWebview .loadUrl(文件:///android_asset/www/index.html);
私有类myWebViewClient扩展WebViewClient
{ //用户访问特定页面后,发送追踪通知Google分析。
@覆盖
公共无效onPageStarted(的WebView视图,字符串URL,位图图标)
{
tracker.trackPageView(mWebview.getUrl());
tracker.dispatch();
}
} }的http://www.the4thdimension.net/2011/11/using-google-analytics-with-html5-or.html
而在谷歌分析的统计数据,你至少应该得到一些信息关于Android操作系统。
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.
解决方案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.
这篇关于Android的应用程序的WebView和谷歌Analytics(分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!