title: Phonegap: how to use Google Analytics without plugin
body: <p>I've got an HTML5 app built with Phonegap and jQueryMobile and I'm testing it for Android. I want to include Analytics, but every approach I take hits roadblocks.</p>
  <p><a href="https://stackoverflow.com/a/14154554/739331">This solution</a> really got me excited: just include a JS file, initialize Analytics in the html , and I'm all set. It looks so very promising. And it works in the browser. But not on my Nexus S running Android 4.1.2.</p>
  <p>I put this script at the end of the document head:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot; src=&quot;GALocalStorage.js&quot;&gt;&lt;/script&gt;
  &lt;script&gt;
      ga_storage._setAccount('UA-XXXXXXXX-1');  
      ga_storage._trackPageview('/index.html');
      ga_storage._trackEvent('Startup','Starting scripts all loaded')
  &lt;/script&gt;
  </code></pre>
  <p>Early on during the app startup, I get these encouraging debug signs:</p>
  <pre><code>09-05 21:47:49.558: V/GAV3(22963): Thread[GAThread,5,main]: connecting to Analytics service
  09-05 21:47:49.609: V/GAV3(22963): Thread[GAThread,5,main]: connect: bindService returned true for Intent { act=com.google.android.gms.analytics.service.START (has extras) }
  09-05 21:47:49.656: V/GAV3(22963): Thread[GAThread,5,main]: Loaded clientId
  ...
  09-05 21:47:49.660: I/GAV3(22963): Thread[GAThread,5,main]: No campaign data found.
  09-05 21:47:49.664: V/GAV3(22963): Thread[GAThread,5,main]: putHit called
  </code></pre>
  <p>Shortly after that appear a number of &quot;Unknown Chromium error: 0&quot;. When I set GALocalStorage to debug mode, I see that this is almost always right behind a &quot;Tracking event&quot;.</p>
  <p>Then, much later, these lines show up:</p>
  <pre><code>09-05 21:47:52.558: V/GAV3(22963): Thread[Failed Connect,5,main]: falling back to local store
  09-05 21:47:52.609: V/GAV3(22963): Thread[GAThread,5,main]: Sending hit to store  PATH: https:  PARAMS: v=1,  ul=nl-nl,  t=appview,  ht=1378410463883,  sr=480x800,  an=True-Budget,  tid=UA-XXXXXXX-1,  aid=com.mappingtheforest.truebudget,  cid=c1c63a4d-0dfd-48fb-9e8a-1371e06d28b4,  av=1.0.0,  _u=.KnL,  
  09-05 21:47:52.777: V/GAV3(22963): Thread[GAThread,5,main]: PowerSaveMode initiated.
  09-05 21:47:52.937: V/GAV3(22963): Thread[GAThread,5,main]: PowerSaveMode terminated.
  09-05 21:47:52.937: V/GAV3(22963): Thread[GAThread,5,main]: Dispatch running...
  09-05 21:47:52.976: V/GAV3(22963): Thread[GAThread,5,main]: User-Agent: GoogleAnalytics/3.0 (Linux; U; Android 4.1.2; nl-nl; Nexus S Build/JZO54K)
  09-05 21:47:52.976: V/GAV3(22963): Host: ssl.google-analytics.com
  09-05 21:47:52.976: V/GAV3(22963): GET /collect?v=1&amp;ul=nl-nl&amp;t=appview&amp;ht=1378410463883&amp;sr=480x800&amp;an=True-Budget&amp;tid=UA-XXXXXXXX-1&amp;aid=com.mappingtheforest.truebudget&amp;cid=c1c63a4d-0dfd-48fb-9e8a-1371e06d28b4&amp;av=1.0.0&amp;_u=.KnL&amp;_v=ma3.0.0&amp;qt=9079&amp;z=1 HTTP/1.1
  </code></pre>
  <p>I've already made sure that the google-analytics.com domain is whitelisted in Phonegap's config.xml file.</p>
  <p>What's going on?</p>