Google Analytics in an iPhone webapp gone native
April 27, 2010 6:40 AM
How can I make Google Analytics + event tracking work from without a webapp-as-native-application on the iPhone? I think it doesn't report a domain.
I'm working on a native iPhone application which is really a webapp wrapped in Phonegap. I want to use Google Analytics to track how many times the app data is loaded from the web, and hopefully track events such as how often certain sections of the app are used.
(I know Google provides an SDK specifically for use with iPhone OS apps, but my app is currently all HTML and JS but for the wrapper, and I'd prefer to keep it that way because I haven't really dug into Obj-C yet.)
I've tried different implementations of the GA script, but as soon as I start testing on the device (or Simulator for that matter) nothing is being reported.
I think it may have something to do with the index.html on the device not having a "domain" as such. "setDomainName("none")" doesn't seem to help here.
Here's my current implementation:
-index.html on the device, in <head>:
-In index.html the application data is collected from the web using Ajax. This loads the contents of a file "content.php" and writes them into the <body>. In this file:
Any ideas how to fix this? I've asked on the respective forums for Analytics and Phonegap but haven't gotten much further.
Thanks in advance for any input.
I'm working on a native iPhone application which is really a webapp wrapped in Phonegap. I want to use Google Analytics to track how many times the app data is loaded from the web, and hopefully track events such as how often certain sections of the app are used.
(I know Google provides an SDK specifically for use with iPhone OS apps, but my app is currently all HTML and JS but for the wrapper, and I'd prefer to keep it that way because I haven't really dug into Obj-C yet.)
I've tried different implementations of the GA script, but as soon as I start testing on the device (or Simulator for that matter) nothing is being reported.
I think it may have something to do with the index.html on the device not having a "domain" as such. "setDomainName("none")" doesn't seem to help here.
Here's my current implementation:
-index.html on the device, in <head>:
<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>
-In index.html the application data is collected from the web using Ajax. This loads the contents of a file "content.php" and writes them into the <body>. In this file:
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
pageTracker._trackEvent('My Delightful App, 'Application', 'Load');
} catch(err) {}</script>
Any ideas how to fix this? I've asked on the respective forums for Analytics and Phonegap but haven't gotten much further.
Thanks in advance for any input.
Well, it's a remote php file, and the contents load fine but when I add the tracking script (ga.js) from there, the data will not load into the app.
posted by goodnewsfortheinsane at 8:32 AM on April 27, 2010
posted by goodnewsfortheinsane at 8:32 AM on April 27, 2010
This thread is closed to new comments.
That is, why does the hit-tracking have to run on the phone, or inside the app at all?
(If you need the app to display its own use of the web for some reason, you can build the data it needs on the website, and just request that (simpler/faster) rather than querying Analytics directly, no?)
posted by rokusan at 6:53 AM on April 27, 2010