Skip to content

Instantly share code, notes, and snippets.

@purplecabbage
Created May 4, 2011 21:23
Show Gist options
  • Save purplecabbage/956066 to your computer and use it in GitHub Desktop.
Save purplecabbage/956066 to your computer and use it in GitHub Desktop.
GoogleAnalyticsPhoneGapPlugin
<script type="text/javascript" charset="utf-8" src="GoogleAnalyticsPlugin.js"></script>
<script type="text/javascript" charset="utf-8">
var googleAnalytics;
function onBodyLoad()
{
document.addEventListener("deviceready",onDeviceReady,false);
}
/* When this function is called, PhoneGap has been initialized and is ready to roll */
function onDeviceReady()
{
// do your thing!
googleAnalytics = window.plugins.googleAnalyticsPlugin;
googleAnalytics.startTrackerWithAccountID("UA-YOURCODEHERE");
googleAnalytics.trackPageview("/application/launch");
}
// example of tracking an event in your app
googleAnalytics.trackEvent("Videos","Play","Take On Me: Literal Video Version",1);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment