Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 76 lines (61 sloc) 3.24 KB
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
<script type="text/javascript" src="GAPlugin.js"></script>
<script type="text/javascript">
var gaPlugin;
function initialize() {
document.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady() {
gaPlugin = window.plugins.gaPlugin;
// Note: A request for permission is REQUIRED by google. You probably want to do this just once, though, and remember the answer for subsequent runs.
navigator.notification.confirm('GA_PLUGIN would like your permission to collect usage data. No personal or user identifiable data will be collected.', permissionCallback, 'Attention', 'Allow,Deny');
function permissionCallback (button) {
if (button === 1)
gaPlugin.init(nativePluginResultHandler, nativePluginErrorHandler, "UA-12345678-1", 10);
function nativePluginResultHandler (result) {
//alert('nativePluginResultHandler - '+result);
console.log('nativePluginResultHandler: '+result);
function nativePluginErrorHandler (error) {
//alert('nativePluginErrorHandler - '+error);
console.log('nativePluginErrorHandler: '+error);
function TrackButtonClicked() {
gaPlugin.trackEvent( nativePluginResultHandler, nativePluginErrorHandler, "Button", "Click", "event only", 1);
function VariableButtonClicked() {
// Set a dimension based on index and value. Make sure you have added a dimension in the GA dashboard to the
// default property for the passed in index, and your desired scope. GA allows up to 20 dimensions for a free account
gaPlugin.setVariable( nativePluginResultHandler, nativePluginErrorHandler, 1, "Purple");
// dimensions are are passed to the next event sent to GA. go ahead and fire off an event with the label (key) of your choice
// In this example, the label for custom dimension 1 will show up in the dashboard as "favoriteColor". This is much more efficent
// than the old custom variable method introduced in V1, (plus you get 20 free dimensions vs 5 free custom variables)
gaPlugin.trackEvent( nativePluginResultHandler, nativePluginErrorHandler, "event with variable", "set variable", "favoriteColor", 1);
function PageButtonClicked() {
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "");
function goingAway() {
gaPlugin.exit(nativePluginResultHandler, nativePluginErrorHandler);
<body onload="initialize();" onunload="goingAway();" id="stage" class="theme">
<h1>Test Google Analytics Plugin</h1>
<div class="space"></div>
<a href="#" class="btn large" onclick="TrackButtonClicked();">Track Event</a>
<a href="#" class="btn large" onclick="VariableButtonClicked();">Track Event with Variable</a>
<a href="#" class="btn large" onclick="PageButtonClicked();">Track Page</a>