public void initialiseAnalytics(final String analyticsAccount, final
String domainName) {
Element firstScript =
Document.get().getElementsByTagName("script").getItem(0);
String scriptContent =
"var _gaq = _gaq || [];" +
"_gaq.push(['_setAccount', '" + analyticsAccount + "']);" +
"_gaq.push(['_setDomainName', '" + domainName + "']);" +
"_gaq.push(['_trackPageview']);";
ScriptElement config =
Document.get().createScriptElement(scriptContent);
firstScript.getParentNode().insertBefore(config, firstScript);
ScriptElement script = Document.get().createScriptElement();
// Add the google analytics script.
script.setSrc(("https:".equals(Window.Location.getProtocol())
? "https://ssl" : "http://www") + ".google-analytics.com/
ga.js");
script.setType("text/javascript");
script.setAttribute("async", "true");
firstScript.getParentNode().insertBefore(script, firstScript);
}
On Jan 26, 10:04 am, Dugald <dugald.mor...@gmail.com> wrote:
> I have created a very simple test at the following location:
>
> http://www.councilmapserver.com/gwt-analytics/GWT_Analytics_Test.html
>
> It is a GWT application that makes a call to the method detailed at
> the start of this thread. It has been compiled without obfuscation so
> that hopefully someone can help work out why the Google Analytics code
> isn't sending the tracking beacon (making the__utm.gifGET request).
>
> On Jan 26, 9:19 am, Raphael André Bauer
>
>
>
>
>
>
>
> <raphael.andre.ba...@gmail.com> wrote:
> > Not sure what is going on,
>
> > but that's the way gwtp is doing Google Analytics:http://code.google.com/p/gwt-platform/source/browse/gwtp-core/gwtp-mv...
>
> > ra
>
> > On Wed, Jan 25, 2012 at 10:53 PM, Dugald <dugald.mor...@gmail.com> wrote:
>
> > > Fromhttp://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI...,
> > > it says:
>
> > > Your compiled script runs in a nested frame, and $wnd and $doc are
> > > automatically initialized to correctly refer to the host page's window
> > > and document.
>
> > > Can someone perhaps tell me if they this this is the reason why the
> > > code isn't running as expected.
>
> > > On Jan 25, 2:42 pm, Dugald <dugald.mor...@gmail.com> wrote:
> > >> I have a GWT application (http://www.councilmapserver.com/cms-demo/
> > >> CMS.html) in which I dynamically configure the analytics code. The
> > >> code is as follows:
>
> > >> private native void initialiseAnalytics(final String analyticsAccount,
> > >> final String domainName) /*-{
> > >> try {
> > >> $wnd._gaq = $wnd._gaq || [];
> > >> $wnd._gaq.push(['_setAccount', analyticsAccount]);
> > >> $wnd._gaq.push(['_setDomainName', domainName]);
> > >> $wnd._gaq.push(['_trackPageview']);
> > >> (function() {
> > >> var ga = document.createElement('script');
> > >> ga.type = 'text/javascript';
> > >> ga.async = true;
> > >> ga.src = ('https:' == document.location.protocol ? 'https://
> > >> ssl' : 'http://www') + '.google-analytics.com/ga.js';
> > >> var s = document.getElementsByTagName('script')[0];
> > >> s.parentNode.insertBefore(ga, s);
> > >> })();
> > >> } catch (e) {
> > >> $wnd.alert("JSNI method GoogleAnalytics.initialiseAnalytics()
> > >> threw an exception:" + e);
> > >> }
>
> > >> }-*/;
>
> > >> The code executes without reporting any errors, however, the tracking
> > >> beacon is never sent (no GET request for__utm.gifis made).
>
> > >> I have created a similar piece of code with straight HTML and
> > >> JavaScript athttp://www.councilmapserver.com/AnalyticsTest/AnalyticsTest-LateDynam...
> > >> which does result in the tracking beacon being sent. Can anyone shed
> > >> some light into what the differences may be?
>
> > > --
> > > You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> > > To post to this group, send email to google-web-toolkit@googlegroups.com.
> > > To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
> > > For more options, visit this group athttp://groups.google.com/group/google-web-toolkit?hl=en.
>
> > --
> > inc:http://ars-machina.raphaelbauer.com
> > tech:http://ars-codia.raphaelbauer.com
> > web:http://raphaelbauer.com
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment