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

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