日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android Mobile Web 集成 Webtrends

發(fā)布時間:2023/12/10 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android Mobile Web 集成 Webtrends 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

最近,需要在Sencha Touch + Phonegap的架構(gòu)中在Android下集成Webtrends,記錄下一些過程,

查了下官網(wǎng)SDK說明,看起來是支持在混合模式下做點事情的,大概步驟如下,

   

  • Add a custom?WebViewClient?to the?WebView?to handle communication from JavaScript in the embedded web content to the native application.
    • For a basic implementation, use the?extendsWebView?helper method in the?WebtrendsDataCollector?to add the Webtrends custom?WebViewClient: String URL = "file:///android_asset/WebContent/webViewContent.html";
      WebView wv = (WebView)findViewById(R.id.webView1);
      wv.getSettings().setJavaScriptEnabled(true);
      WebtrendsDataCollector.getInstance().extendsWebView(wv); ? ? ?
      wv.loadUrl(URL);
    • If your application uses its own custom WebViewClient, you should not use the?extendsWebView?helper method. Instead, ensure that the?WebtrendsWebViewClient?also gets invoked by following these steps:
  • Modify your custom?WebViewClient?to extend?WebtrendsWebViewClient?instead of?WebViewClient.
  • If you are overriding?onLoadResource, call?super.onLoadResource.
  • Set your custom?WebViewClient?on your?WebView. import android.webkit.WebView;
    import com.webtrends.mobile.analytics.android.webViewExtension.WebtrendsWebViewClient;

    public class MyCustomWebViewClient extends WebtrendsWebViewClient{
    ? ? ? ? @Override
    ? ? ? ? public void onLoadResource(WebView view, String url){
    ? ? ? ? ? ? ? ? super.onLoadResource(view, url);
    ? ? ? ? }
    }
    String URL = "file:///android_asset/WebContent/webViewContent.html";
    WebView wv = (WebView)findViewById(R.id.webView1);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.setWebViewClient(new MyCustomWebViewClient()); ? ? ?
    wv.loadUrl(URL);
  • Add?WebtrendsMobileLib.js?to the content that will be loaded in the?WebView.?WebtrendsMobileLib.js?is delivered as part of the Webtrends Mobile Library for?Android.
  • Use the?WebtrendsLib?to generate events.?In the embedded web content, use the JavaScript helper functions of the?webtrendsLib?object to generate events through the native app. A JavaScript helper function exists for each of the event helper functions exposed in the native Webtrends SDK. The JavaScript helper functions take the same arguments as the native helper functions. <html>
    ? ? ? ? <head>
    ? ? ? ? ? ? ? ? <script type="text/javascript" src="js/WebtrendsMobileLib.js"></script>
    ? ? ? ? ? ? ? ? <script type="text/javascript">
    ? ? ? ? ? ? ? ? ? ? ? ? function sendButtonClickEvent() {
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var eventPath = "/HelloWorld/button/click";
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var eventDesc = "HelloWorld Button Click Event";
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var eventType = "click";
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var customData = {
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? customKey : "CustomValue"
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? };
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? webtrendsLib.onButtonClick(eventPath, eventDesc, eventType,
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?customData);
    ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ?
    ? ? ? ? ? ? ? ? </script> ? ? ? ?
    ? ? ? ? </head>
    ? ? ? ? <body>
    ? ? ? ? ? ? ? ? <div>
    ? ? ? ? ? ? ? ? ? ? ? ? <input type="button" onclick="sendButtonClickEvent()" value="Click Me">
    ? ? ? ? ? ? ? ? ? </input>
    ? ? ? ? ? ? ? ? </div>
    ? ? ? ? </body>
    </html>
  • 這時候問題來了,用了Phonegap后默認MainActivity要繼承CordovaActivity,而如果要集成Webtrends,又得繼承WebtrendsActivity,在Java下面不支持多繼承,怎么搞呢。。。
    看來只能出大招了,把WebtrendsSDK反編譯,

    看起來代碼還不算多,把
    WebtrendsActivity.java里面的代碼拷出來,粘貼到自己新建的的MyWebtrendsActivity.java,然后讓MyWebtrendsActivity繼承CordovaActivity,最后讓MainActivity繼承MyWebtrendsActivity,用組合的方法解決多重繼承,繼續(xù)一番折騰后,it works.

    另一個問題就是如果有了自己的WebClient,還需要去繼承WebtrendsWebViewClient,不幸的是PhoneGap還真實現(xiàn)了自己的WebViewClient,即CordovaWebViewClient,又是同樣的問題,去修改PhoneGap的代碼不現(xiàn)實也不科學。咋搞呢??糾結(jié)了一番后,發(fā)現(xiàn)萬幸的事情,在Webtrends代碼中WebtrendsDataCollector.getInstance().extendsWebView(webView);像上面說的,webview是一個原生的webview,如果有自己的webview,必須繼承WebtrendsWebViewClient。我試了下把CordovaWebView傳進來,也可以,不用自己去實現(xiàn),汗Σ( ° △ °|||)︴ 這兩個問題后,其他都還好。注意在配置中修改timezone以及wt_dc_dcsid是必須的,wt_dc_dcsid需要跟Webtrends拿,估計價格不菲吧,我們是客戶提供的,直接粘貼。

    SDK的下載也比較奇葩,需要發(fā)貼跟管理員申請才能鏈接。








    轉(zhuǎn)載于:https://www.cnblogs.com/yodateam/p/4206022.html

    總結(jié)

    以上是生活随笔為你收集整理的Android Mobile Web 集成 Webtrends的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。