Integrating Google Analytics into GWT application

前端 未结 2 669
走了就别回头了
走了就别回头了 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.

提交回复
热议问题