I have used Phonegap Build and GA plugin recently and I did not face any problem of using it,
here is step by step explanation on using GA plugin.
- first create a google analytics account.
- There Admin -> (Create Account) select “Create new account” from drop down
- select “App” from “What would you like to track?”
- fill the rest of the filed by giving the relevant details
- Hit “Get Tracking ID” and copy paste it to a note pad file
Next, GA is a plugin in phonegap so we need to add it in the config.xml
<gap:plugin name="com.adobe.plugins.gaplugin" />
Here is a complete code for your review
<head>
<script src="cordova.js"></script>
<script src="GAPlugin.js"></script>
<script type="text/javascript" >
document.addEventListener("deviceready", init, false);
var AnalyticsAccount = "UA-12341712-1";
var testDiv;
function errorHandler(e) {
//error handler
}
function successhandler() {
//successhanlder
}
function init() {
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(successhandler, errorHandler, AnalyticsAccount, 10);
//Records event
document.querySelector("#analyticsbutton").addEventListener("click", function(e) {
e.preventDefault();
gaPlugin.trackEvent(function() {
alert("Button event was recorded");
}, errorHandler, "Button", "Click", "Test button was clicked", 11);
});
}
</script>
</head>
<body>
<h1>Analytics Test!!!!!!!!</h1>
<br/>
<button id="analyticsbutton">Test</button><br/>
<br/>
</body>