Add Matomo analytics for page views

This commit is contained in:
Skylar Ittner 2022-01-20 00:39:12 -07:00
parent ac6ac13ec7
commit 1344064d34
4 changed files with 46 additions and 4 deletions

View File

@ -97,6 +97,14 @@ $(document).keyup(function (e) {
router.on("routeChange", function (newRoute) {
console.log("Info", "Navigating to ", newRoute.path);
if (getStorage("analytics") !== "false") {
try {
_paq.push(['setCustomUrl', newRoute.path]);
_paq.push(['trackPageView']);
} catch (ex) {
console.error(ex);
}
}
});
function setAppTheme(theme) {
@ -176,6 +184,27 @@ var setup = (inStorage("accountnumber") && inStorage("accountkey")) || inStorage
app.init();
if (getStorage("analytics") !== "false") {
try {
var _paq = window._paq = window._paq || [];
_paq.push(['enableLinkTracking']);
(function () {
var u = "https://analytics.netsyms.net/";
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', '40']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
} catch (ex) {
// skip
}
} else {
console.log("Analytics code not loaded at user request.");
}
if (setup) {
router.navigate("/home");
} else {

View File

@ -33,6 +33,11 @@ $('.item-content[data-setting=hideaccountnag] .toggle input').on("change", funct
setStorage("hideaccountnag", checked);
});
$('.item-content[data-setting=analytics] .toggle input').on("change", function () {
var checked = $(this).prop('checked');
setStorage("analytics", checked ? "true" : "false");
});
function resetAccountPrompt() {
app.dialog.confirm("Are you sure you want to log out?", function () {
removeFromStorage("accountnumber");

View File

@ -25,9 +25,9 @@
</div>
</div>
<div class="col-100 text-align-center">
<p>Privacy Info: This app doesn't track you or sell your data. We only know
what you actually tell us, and we only use that data to provide and
improve the services we offer you.
<p>Privacy Info: This app doesn't sell your data. We do collect a small amount
of analytics to help improve the app. You can opt out in the
app settings.
</div>
</div>
</div>

View File

@ -345,7 +345,15 @@ var routes = [
text: "",
onclick: "openBrowser('https://helena.express/appterms?mtm_campaign=HelenaExpressApp')",
link: true
});
},
{
setting: "analytics",
title: "Analytics",
text: "If turned on, we'll collect some anonymous information to help improve the app. It is not sent to any third parties.",
toggle: true,
checked: getStorage("analytics") !== "false",
onclick: ""
}, );
resolve({
content: compiledPages.settings({
page_title: "Settings",