Matomo update

This commit is contained in:
silas 2018-10-01 15:17:12 +02:00
parent 699b1a7d7d
commit d37fc8254e
7 changed files with 20 additions and 21 deletions

0
log/gitFile.txt Normal file
View File

View File

@ -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"] || [];

View File

@ -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;

View File

@ -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"] || [];

9
src/js/prod.settings.js Executable file
View File

@ -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;

View File

@ -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;

View File

@ -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);
});