Integrating Google Analytics into GWT application

前端 未结 2 644
走了就别回头了
走了就别回头了 2020-12-30 03:38

This should be totally simple but I can\'t get it working no matter what I try. I\'m trying to use Google Analytics with GWT application. From what I understood, there are t

相关标签:
2条回答
  • 2020-12-30 04:36

    This is just a guess, but you probably need to reference the host page (the one where the Google Analytics JS code has been included) via $wnd in the JSNI, like this:

    public static native void recordAnalyticsHit(String pageName) /*-{
        $wnd.pageTracker._trackPageview(pageName);
    }-*/;
    

    JSNI code (and in general, GWT code) is run in a iframe to keep the namespace clean, that's why you need the $wnd reference to the main window.

    0 讨论(0)
  • 2020-12-30 04:40
    <script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    
    <script type="text/javascript">
       var pageTracker = _gat._getTracker("UA-xxxxxx-x");
       pageTracker._trackPageview("/subdirectory/pagename");
    </script>
    

    See http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55485 for details.

    0 讨论(0)
提交回复
热议问题