日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Android Mobile Web 集成 Webtrends

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

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

查了下官網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,用組合的方法解決多重繼承,繼續一番折騰后,it works.

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

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








    轉載于:https://www.cnblogs.com/yodateam/p/4206022.html

    總結

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

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。