Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GAPlugin.js Phonegap3 compliant #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<license>MIT</license>

<js-module src="www/GAPlugin.js" name="GAPlugin">
<clobbers target="GAPlugin" />
<clobbers target="plugins.gaPlugin" />
</js-module>

<engines>
Expand Down
91 changes: 40 additions & 51 deletions www/GAPlugin.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,47 @@
(function(){
var cordovaRef = window.PhoneGap || window.Cordova || window.cordova;
var exec = require("cordova/exec");

function GAPlugin() { }
function GAPlugin() { }

// initialize google analytics with an account ID and the min number of seconds between posting
//
// id = the GA account ID of the form 'UA-00000000-0'
// period = the minimum interval for transmitting tracking events if any exist in the queue
GAPlugin.prototype.init = function(success, fail, id, period) {
return cordovaRef.exec(success, fail, 'GAPlugin', 'initGA', [id, period]);
};
// initialize google analytics with an account ID and the min number of seconds between posting
//
// id = the GA account ID of the form 'UA-00000000-0'
// period = the minimum interval for transmitting tracking events if any exist in the queue
GAPlugin.prototype.init = function(success, fail, id, period) {
return exec(success, fail, 'GAPlugin', 'initGA', [id, period]);
};

// log an event
//
// category = The event category. This parameter is required to be non-empty.
// eventAction = The event action. This parameter is required to be non-empty.
// eventLabel = The event label. This parameter may be a blank string to indicate no label.
// eventValue = The event value. This parameter may be -1 to indicate no value.
GAPlugin.prototype.trackEvent = function(success, fail, category, eventAction, eventLabel, eventValue) {
return cordovaRef.exec(success, fail, 'GAPlugin', 'trackEvent', [category, eventAction, eventLabel, eventValue]);
};
// log an event
//
// category = The event category. This parameter is required to be non-empty.
// eventAction = The event action. This parameter is required to be non-empty.
// eventLabel = The event label. This parameter may be a blank string to indicate no label.
// eventValue = The event value. This parameter may be -1 to indicate no value.
GAPlugin.prototype.trackEvent = function(success, fail, category, eventAction, eventLabel, eventValue) {
return exec(success, fail, 'GAPlugin', 'trackEvent', [category, eventAction, eventLabel, eventValue]);
};


// log a page view
//
// pageURL = the URL of the page view
GAPlugin.prototype.trackPage = function(success, fail, pageURL) {
return cordovaRef.exec(success, fail, 'GAPlugin', 'trackPage', [pageURL]);
};
// log a page view
//
// pageURL = the URL of the page view
GAPlugin.prototype.trackPage = function(success, fail, pageURL) {
return exec(success, fail, 'GAPlugin', 'trackPage', [pageURL]);
};

// Set a custom variable. The variable set is included with
// the next event only. If there is an existing custom variable at the specified
// index, it will be overwritten by this one.
//
// value = the value of the variable you are logging
// index = the numerical index of the dimension to which this variable will be assigned (1 - 20)
// Standard accounts support up to 20 custom dimensions.
GAPlugin.prototype.setVariable = function(success, fail, index, value) {
return cordovaRef.exec(success, fail, 'GAPlugin', 'setVariable', [index, value]);
};
// Set a custom variable. The variable set is included with
// the next event only. If there is an existing custom variable at the specified
// index, it will be overwritten by this one.
//
// value = the value of the variable you are logging
// index = the numerical index of the dimension to which this variable will be assigned (1 - 20)
// Standard accounts support up to 20 custom dimensions.
GAPlugin.prototype.setVariable = function(success, fail, index, value) {
return exec(success, fail, 'GAPlugin', 'setVariable', [index, value]);
};

GAPlugin.prototype.exit = function(success, fail) {
return exec(success, fail, 'GAPlugin', 'exitGA', []);
};

GAPlugin.prototype.exit = function(success, fail) {
return cordovaRef.exec(success, fail, 'GAPlugin', 'exitGA', []);
};

if (cordovaRef)
{
cordovaRef.addConstructor(function() {
if(!window.plugins) {
window.plugins = {};
}
if(!window.plugins.gaPlugin) {
window.plugins.gaPlugin = new GAPlugin();
}
});
}
})(); /* End of Temporary Scope. */
var gaPlugin = new GAPlugin();
module.exports = gaPlugin;