-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTracker.js
More file actions
99 lines (90 loc) · 2.7 KB
/
Tracker.js
File metadata and controls
99 lines (90 loc) · 2.7 KB
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
96
97
98
99
var Alloy = require('alloy'),
_ = Alloy._,
Backbone = Alloy.Backbone,
GA = require('analytics.google');
//GA.optOut = true;
GA.debug = false;
GA.trackUncaughtExceptions = true;
var GoogleTracker = GA.getTracker(Alloy.CFG.gaTrackingID);
module.exports = {
/**
* Track a screen
*
* @param {String} name The name of the application screen.
*
*/
trackScreen: function(name) {
GoogleTracker.trackScreen(name);
},
/**
* Track an event
*
* @param {String} category The event category
* @param {String} [action] The event action
* @param {String} [label] The event label
* @param {Number} [value] The event value
*/
trackEvent: function(category, action, label, value) {
GoogleTracker.trackEvent({
category: category,
action: action || '',
label: label || '',
value: value || 1
});
},
/**
* Track social media interaction
*
* @param {String} platform The social network with which the user is interacting (e.g. Facebook, Google+, Twitter, etc.).
* @param {String} action The social action taken (e.g. Like, Share, +1, etc.).
* @param {String} [target] The content on which the social action is being taken (i.e. a specific article or video).
*/
trackSocial: function(platform, action, target) {
GoogleTracker.trackSocial({
network: platform,
action: action,
target: target || ''
});
},
/**
* [trackTime description]
*
* @param {[type]} category [description]
* @param {[type]} interval [description]
*
* @return {[type]} [description]
*/
trackLoadingTime: function(category, interval) {
GoogleTracker.trackTime({
category: category,
time: interval || 0
});
},
/**
* [trackTransaction description]
*
* @param {Object} config Configuration object
* @param {String} config.id A unique ID representing the transaction. This ID should not collide with other transaction IDs.
* @param {String} [config.affiliation="In-app Store"] An entity with which the transaction should be affiliated (e.g. a particular store)
* @param {Number} config.revenue The total revenue of a transaction, including tax and shipping
* @param {String} config.name The name of the product
* @param {String} [config.sku] The SKU of the product
* @param {String} [config.category] A category to which the product belongs
*/
trackTransaction: function(config) {
var transaction = GA.createTransaction(config.id, {
affiliation: config.affiliation || 'In-app Store',
revenue: config.revenue,
tax: 0,
shipping: 0
});
transaction.addItem({
sku: config.sku || config.type + '_' + config.name,
name: config.name,
category: config.category,
price: config.revenue,
quantity: 1
});
GoogleTracker.trackTransaction(transaction);
}
};