-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics.js
executable file
·95 lines (84 loc) · 2.68 KB
/
analytics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2006-2011 Worklight, Ltd.
*/
/**
* Constructor
*/
var Analytics = function () {};
/**
* Initialize Google Analytics configuration
*
* @param accountId The Google Analytics account id
* @param successCallback The success callback
* @param failureCallback The error callback
*/
Analytics.prototype.start = function(accountId, successCallback, failureCallback) {
return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
'start',
[accountId]);
};
/**
* Track a page view on Google Analytics
* @param key The name of the tracked item (can be a url or some logical name).
* The key name will be presented in Google Analytics report.
* @param successCallback The success callback
* @param failureCallback The error callback
*/
Analytics.prototype.trackPageview = function(key, successCallback, failureCallback) {
return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
'trackPageView',
[key]);
};
/**
* Track an event on Google Analytics
* @param category The name that you supply as a way to group objects that you want to track
* @param action The name the type of event or interaction you want to track for a particular web object
* @param label Provides additional information for events that you want to track (optional)
* @param value Assign a numerical value to a tracked page object (optional)
* @param successCallback The success callback
* @param failureCallback The error callback
*/
Analytics.prototype.trackEvent = function(category, action, label, value, successCallback, failureCallback){
return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
'trackEvent',
[
category,
action,
typeof label === "undefined" ? "" : label,
(isNaN(parseInt(value,10))) ? 0 : parseInt(value, 10)
]);
};
Analytics.prototype.setCustomVar = function(index, label, value, scope, successCallback, failureCallback){
return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
'setCustomVariable',
[
(isNaN(parseInt(index,10))) ? 0 : parseInt(index, 10),
label,
value,
(isNaN(parseInt(scope,10))) ? 0 : parseInt(scope, 10)
]);
};
/**
* Load Analytics
*/
if(!window.plugins) {
window.plugins = {};
}
if (!window.plugins.analytics) {
window.plugins.analytics = new Analytics();
}