summaryrefslogtreecommitdiffstats
path: root/theme/javascript/utils/analytic.js
blob: 6c6155a73b80620c790b3208ddd2e1308609b119 (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
31
32
33
define([
    "lodash",
    "mixpanel"
], function(_, mixpanel) {
    mixpanel.init("01eb2b950ae09a5fdb15a98dcc5ff20e", {
        loaded: function() {
            track("page.start");
        }
    });

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

    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
    };
});