/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


function sendErrorReport(category, error, errordata) {
    if (getStorage("analytics") !== "false") {
        try {
            if (typeof errordata == "undefined") {
                _paq.push(['trackEvent', 'Error', category, error]);
            } else {
                _paq.push(['trackEvent', 'Error', category, error, errordata]);
            }
        } catch (ex) {
            console.error(ex);
        }
    }
}

function sendActionReport(category, action, data) {
    if (getStorage("analytics") !== "false") {
        try {
            if (typeof data == "undefined") {
                _paq.push(['trackEvent', 'User Action', category, action]);
            } else {
                _paq.push(['trackEvent', 'User Action', category, action, data]);
            }
        } catch (ex) {
            console.error(ex);
        }
    }
}

function trackPageView(url, title) {
    if (getStorage("analytics") !== "false") {
        try {
            _paq.push(['setCustomUrl', "https://app.helena.express" + url]);
            _paq.push(['setDocumentTitle', title]);
            _paq.push(['trackPageView']);
        } catch (ex) {
            console.error(ex);
        }
    }
}

function privacyPromptDialog() {
    app.dialog.confirm("Turn off anonymous reporting?", "Analytics", function () {
        setStorage("analytics", "false");
        app.toast.show({
            text: "Analytics disabled.",
            closeTimeout: 3000
        });
    });
}