<?php
/* * * * * * * * * * * * * * * * * * * *
 *  ██████╗ █████╗  ██████╗ ███████╗
 * ██╔════╝██╔══██╗██╔═══██╗██╔════╝
 * ██║     ███████║██║   ██║███████╗
 * ██║     ██╔══██║██║   ██║╚════██║
 * ╚██████╗██║  ██║╚██████╔╝███████║
 *  ╚═════╝╚═╝  ╚═╝ ╚═════╝ ╚══════╝
 *
 * @author   : Daan van den Bergh
 * @url      : https://ffw.press/wordpress/caos/
 * @copyright: (c) 2021 Daan van den Bergh
 * @license  : GPL2v2 or later
 * * * * * * * * * * * * * * * * * * * */

$endpoint = apply_filters('caos_minimal_analytics_endpoint', 'https://www.google-analytics.com/collect');

/**
 * The below script is maintained by: https://minimalanalytics.com/
 */
?>
<script>
    (function(a, b, c) {
        var d = a.history,
            e = document,
            f = navigator || {},
            g = localStorage,
            h = encodeURIComponent,
            i = d.pushState,
            k = function() {
                return Math.random().toString(36)
            },
            l = function() {
                return g.cid || (g.cid = k()), g.cid
            },
            m = function(r) {
                var s = [];
                for (var t in r)
                    r.hasOwnProperty(t) && void 0 !== r[t] && s.push(h(t) + "=" + h(r[t]));
                return s.join("&")
            },
            n = function(r, s, t, u, v, w, x) {
                var z = "<?= $endpoint; ?>",
                    A = m({
                        v: "1",
                        ds: "web",
                        aip: c.anonymizeIp ? 1 : void 0,
                        tid: b,
                        cid: l(),
                        t: r || "pageview",
                        sd: c.colorDepth && screen.colorDepth ? screen.colorDepth + "-bits" : void 0,
                        dr: e.referrer ||
                            void 0,
                        dt: e.title,
                        dl: e.location.origin + e.location.pathname + e.location.search,
                        ul: c.language ?
                            (f.language || "").toLowerCase() : void 0,
                        de: c.characterSet ? e.characterSet : void 0,
                        sr: c.screenSize ? (a.screen || {}).width + "x" + (a.screen || {}).height : void 0,
                        vp: c.screenSize &&
                            a.visualViewport ? (a.visualViewport || {}).width + "x" + (a.visualViewport || {}).height : void 0,
                        ec: s || void 0,
                        ea: t || void 0,
                        el: u || void 0,
                        ev: v || void 0,
                        exd: w || void 0,
                        exf: "undefined" != typeof x &&
                            !1 == !!x ? 0 : void 0
                    });
                if (f.sendBeacon) f.sendBeacon(z, A);
                else {
                    var y = new XMLHttpRequest;
                    y.open("POST", z, !0), y.send(A)
                }
            };
        d.pushState = function(r) {
                return "function" == typeof d.onpushstate &&
                    d.onpushstate({
                        state: r
                    }), setTimeout(n, c.delay || 10), i.apply(d, arguments)
            }, n(),
            a.ma = {
                trackEvent: function o(r, s, t, u) {
                    return n("event", r, s, t, u)
                },
                trackException: function q(r, s) {
                    return n("exception", null, null, null, null, r, s)
                }
            }
    })
    (window, "<?= CAOS_OPT_TRACKING_ID; ?>", {
        anonymizeIp: <?= CAOS_OPT_ANONYMIZE_IP_MODE == 'one' ? 'true' : 'false'; ?>,
        siteSpeedSampleRate: <?= CAOS_OPT_SITE_SPEED_SAMPLE_RATE; ?>,
        colorDepth: true,
        characterSet: true,
        screenSize: true,
        language: true
    })
    <?php if (CAOS_OPT_ADJUSTED_BOUNCE_RATE) : ?>
        setTimeout("ma.trackEvent('adjusted bounce rate', '<?= CAOS_OPT_ADJUSTED_BOUNCE_RATE . ' seconds'; ?>')", <?= CAOS_OPT_ADJUSTED_BOUNCE_RATE * 1000; ?>);
    <?php endif; ?>
    <?php if (CAOS_OPT_EXT_TRACK_AD_BLOCKERS) : ?>
        var event = new Event('caos_track_ad_blockers');
        document.dispatchEvent(event);
    <?php endif; ?>
</script>