summaryrefslogtreecommitdiffstats
path: root/theme/javascript/utils/analytic.js
blob: f90dd95ed92f921d1ae24c1653d9214ecb52c6e2 (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
34
35
36
define([
    "lodash"
], function(_) {
    var isAvailable = function() {
        return (
            typeof mixpanel !== "undefined" &&
            typeof mixpanel.track === "function"
        );
    };

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

    setTimeout(function() {
        mixpanel.init("01eb2b950ae09a5fdb15a98dcc5ff20e");
        track("page.start");
    }, 0);   

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