From d37fc8254efa0f1473805856b5ff6ef15c519319 Mon Sep 17 00:00:00 2001 From: silas Date: Mon, 1 Oct 2018 15:17:12 +0200 Subject: [PATCH] Matomo update --- log/gitFile.txt | 0 public/js/app.js | 11 ++--------- prod.settings.js => src/js/beta.settings.js | 3 +++ src/js/lib/pwa-assets.js | 11 ++--------- src/js/prod.settings.js | 9 +++++++++ src/js/settings.js | 3 ++- test/test.testcafe.js | 4 ++-- 7 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 log/gitFile.txt rename prod.settings.js => src/js/beta.settings.js (78%) create mode 100755 src/js/prod.settings.js diff --git a/log/gitFile.txt b/log/gitFile.txt new file mode 100644 index 0000000..e69de29 diff --git a/public/js/app.js b/public/js/app.js index ca39607..0bcc033 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -4606,13 +4606,11 @@ class Matomo { static init() { Matomo.isTrackingPromise = new Promise(async (resolve) => { let shouldTrack = localStorage.getItem(Matomo.LOCAL_STORAGE_KEY); - console.log(shouldTrack,Helper.isNull(shouldTrack)); if (Helper.isNull(shouldTrack)) { shouldTrack = await Matomo._askIsTracking(); localStorage.setItem(Matomo.LOCAL_STORAGE_KEY, shouldTrack); } else { - console.log(shouldTrack, (shouldTrack === "1")); shouldTrack = (shouldTrack === "1"); Matomo.setTrack(shouldTrack); } @@ -4622,7 +4620,7 @@ class Matomo { Matomo.push(['trackPageView']); Matomo.push(['enableLinkTracking']); Matomo.push(['setTrackerUrl', Matomo.TRACK_SITE + '/piwik.php']); - Matomo.push(['setSiteId', '1']); + Matomo.push(['setSiteId', Matomo.SIDE_ID]); let d = document, g = d.createElement('script'), s = d.getElementsByTagName('head')[0]; g.type = 'text/javascript'; @@ -4634,7 +4632,6 @@ class Matomo { } static async _askIsTracking() { - console.log(Matomo.TRACK_SITE + Matomo.BASE_PATH + "isTracked"); Matomo.isTrackingPromise = Matomo.query("isTracked") .then(xml => { let textContent = xml.firstChild.textContent; @@ -4646,13 +4643,8 @@ class Matomo { static async query(method) { return fetch(Matomo.TRACK_SITE + Matomo.BASE_PATH + method, { - // "method":"POST", "mode": "cors", "credentials": "include", - // "headers": { - // 'Access-Control-Allow-Origin': '*', - // 'Access-Control-Allow-Credentials': 'true', - // }, }).then(res => res.text()).then(text => (new window.DOMParser()).parseFromString(text, "text/xml")); } @@ -4676,6 +4668,7 @@ class Matomo { Matomo.LOCAL_STORAGE_KEY = "matomoShouldTrack"; Matomo.TRACK_SITE = "//matomo.silas.link"; Matomo.BASE_PATH = "/index.php?module=API&method=AjaxOptOut."; +Matomo.SIDE_ID = "1"; InitPromise.addPromise(() => { window["_paq"] = window["_paq"] || []; diff --git a/prod.settings.js b/src/js/beta.settings.js similarity index 78% rename from prod.settings.js rename to src/js/beta.settings.js index d8b6874..48ca04e 100755 --- a/prod.settings.js +++ b/src/js/beta.settings.js @@ -1,6 +1,9 @@ import {SystemSettings, Translator} from "./lib/pwa-lib"; +import {Matomo} from "./lib/pwa-assets"; SystemSettings.setBasePath("/"); Translator.supportedLanguages = ["de"]; Translator.markTranslations = false; Translator.markUntranslatedTranslations = false; + +Matomo.SIDE_ID = 1; \ No newline at end of file diff --git a/src/js/lib/pwa-assets.js b/src/js/lib/pwa-assets.js index 35b1a5a..1dc16e3 100755 --- a/src/js/lib/pwa-assets.js +++ b/src/js/lib/pwa-assets.js @@ -13,13 +13,11 @@ class Matomo { static init() { Matomo.isTrackingPromise = new Promise(async (resolve) => { let shouldTrack = localStorage.getItem(Matomo.LOCAL_STORAGE_KEY); - console.log(shouldTrack,Helper.isNull(shouldTrack)); if (Helper.isNull(shouldTrack)) { shouldTrack = await Matomo._askIsTracking(); localStorage.setItem(Matomo.LOCAL_STORAGE_KEY, shouldTrack); } else { - console.log(shouldTrack, (shouldTrack === "1")); shouldTrack = (shouldTrack === "1"); Matomo.setTrack(shouldTrack); } @@ -29,7 +27,7 @@ class Matomo { Matomo.push(['trackPageView']); Matomo.push(['enableLinkTracking']); Matomo.push(['setTrackerUrl', Matomo.TRACK_SITE + '/piwik.php']); - Matomo.push(['setSiteId', '1']); + Matomo.push(['setSiteId', Matomo.SIDE_ID]); let d = document, g = d.createElement('script'), s = d.getElementsByTagName('head')[0]; g.type = 'text/javascript'; @@ -41,7 +39,6 @@ class Matomo { } static async _askIsTracking() { - console.log(Matomo.TRACK_SITE + Matomo.BASE_PATH + "isTracked"); Matomo.isTrackingPromise = Matomo.query("isTracked") .then(xml => { let textContent = xml.firstChild.textContent; @@ -53,13 +50,8 @@ class Matomo { static async query(method) { return fetch(Matomo.TRACK_SITE + Matomo.BASE_PATH + method, { - // "method":"POST", "mode": "cors", "credentials": "include", - // "headers": { - // 'Access-Control-Allow-Origin': '*', - // 'Access-Control-Allow-Credentials': 'true', - // }, }).then(res => res.text()).then(text => (new window.DOMParser()).parseFromString(text, "text/xml")); } @@ -83,6 +75,7 @@ class Matomo { Matomo.LOCAL_STORAGE_KEY = "matomoShouldTrack"; Matomo.TRACK_SITE = "//matomo.silas.link"; Matomo.BASE_PATH = "/index.php?module=API&method=AjaxOptOut."; +Matomo.SIDE_ID = "1"; InitPromise.addPromise(() => { window["_paq"] = window["_paq"] || []; diff --git a/src/js/prod.settings.js b/src/js/prod.settings.js new file mode 100755 index 0000000..ab1b231 --- /dev/null +++ b/src/js/prod.settings.js @@ -0,0 +1,9 @@ +import {SystemSettings, Translator} from "./lib/pwa-lib"; +import {Matomo} from "./lib/pwa-assets"; + +SystemSettings.setBasePath("/"); +Translator.supportedLanguages = ["de"]; +Translator.markTranslations = false; +Translator.markUntranslatedTranslations = false; + +Matomo.SIDE_ID = null; \ No newline at end of file diff --git a/src/js/settings.js b/src/js/settings.js index a319057..5e151b2 100755 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -1,4 +1,5 @@ import {SystemSettings, Translator} from "./lib/pwa-lib"; +import {Matomo} from "./lib/pwa-assets"; let basePath = "/pwa/wordRotator/public/"; @@ -11,4 +12,4 @@ SystemSettings.setBasePath(basePath); Translator.supportedLanguages = ["de"]; Translator.markTranslations = false; -const TRACKING_ID = ''; +Matomo.SIDE_ID = 2; diff --git a/test/test.testcafe.js b/test/test.testcafe.js index 9d1a7cc..77e925c 100644 --- a/test/test.testcafe.js +++ b/test/test.testcafe.js @@ -23,7 +23,7 @@ async function afterEachTest(t) { return await t.eval(() => indexedDB.deleteDatabase('wordRotator')); } -let isLocal = true; +let isLocal = false; if (isLocal) { fixture`Play` .page`https://127.0.0.1/pwa/wordRotator/publicTest/`.beforeEach(async t => { @@ -40,7 +40,7 @@ else { password: '20luxl200' }).beforeEach(async t => { await beforeEachTest(t); - await t.wait(20000); + await t.wait(25000); }).afterEach(async t => { await afterEachTest(t); });