summaryrefslogtreecommitdiffstats
path: root/theme/javascript/utils/analytic.js
blob: cfd0dac4d42579b19ce47abab91fce16baf12852 (plain)
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
define([
    "lodash",
    "mixpanel"
], function(_, mixpanel) {
    mixpanel.init("01eb2b950ae09a5fdb15a98dcc5ff20e", {
        loaded: function() {
            track("View");
        }
    });

    var isAvailable = function() {
        return (typeof mixpanel !== "undefined");
    };

    var track = function(e, data) {
        if (!isAvailable()) {
            console.warn("tracking not available!");
            return;
        }
        console.log("track", e);
        mixpanel.track(e, _.extend(data || {}, {
            'domain': window.location.host
        }));
    };

    return {
        isAvailable: isAvailable,
        track: track
    };
});