-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics.js
64 lines (53 loc) · 1.96 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
(function(w, _cxApiPlugin) {
if (w[_cxApiPlugin]) {
return;
}
var _cxApiProxy = function(experimentId, methodName, args, config, callback, errback) {
return w[w["_cxApiObject"] || "_cxApi"].apply(this, [experimentId, methodName, args, config || this.config, callback, errback]);
};
var Experiment = w[_cxApiPlugin] = function(tracker, config) {
this.tracker = tracker;
this.config = config;
};
Experiment.prototype.chooseVariation = function(experimentId, config, callback, errback) {
var self = this;
return _cxApiProxy.call(self, experimentId, "chooseVariation", [], config, function(result) {
self.tracker.send({
"hitType": "event",
"nonInteraction": true,
"eventCategory": "experiment",
"eventAction": "chooseVariation",
"eventValue": result
});
try {
callback(result);
} catch (e) {
errback(e);
}
}, errback);
};
Experiment.prototype.setChosenVariation = function(experimentId, chosenVariation, config, callback, errback) {
var self = this;
return _cxApiProxy.call(self, experimentId, "setChosenVariation", [chosenVariation], config, function(result) {
self.tracker.send({
"hitType": "event",
"nonInteraction": true,
"eventCategory": "experiment",
"eventAction": "setChosenVariation",
"eventValue": result
});
try {
callback(result);
} catch (e) {
errback(e);
}
}, errback);
};
Experiment.prototype.getChosenVariation = function(experimentId, config, callback, errback) {
return _cxApiProxy.call(this, experimentId, "getChosenVariation", [], config, callback, errback);
};
Experiment.prototype.cxApi = function(experimentId, config, callback, errback) {
return _cxApiProxy.call(this, experimentId, "cxApi", [], config, callback, errback);
};
w[w["GoogleAnalyticsObject"] || "ga"]("provide", "experiment", Experiment);
})(window, "_cxApiPlugin");