Skip to content
Snippets Groups Projects
Commit 9dc05ecd authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Merge branch 'matomo-component' into 'master'

Matomo web component

See merge request !2
parents 0e0c67ea fb24d424
Branches
No related tags found
1 merge request!2Matomo web component
Pipeline #13079 passed
{
"matomo": {
}
}
\ No newline at end of file
import {Matomo} from './matomo.js';
export {Matomo};
\ No newline at end of file
import {i18n} from './i18n.js';
import {LitElement} from "lit-element";
import DBPLitElement from 'dbp-common/dbp-lit-element';
import {EventBus} from 'dbp-common';
import buildInfo from 'consts:buildInfo';
export class MatomoElement extends DBPLitElement {
constructor() {
super();
this.endpoint = '';
this.siteId = -1;
this.isRunning = false;
this.lastEvent = [];
}
static get properties() {
return {
endpoint: { type: String },
siteId: { type: Number, attribute: 'site-id' },
};
}
connectedCallback() {
super.connectedCallback();
this._bus = new EventBus();
this._bus.subscribe('auth-update', (data) => {
this.setupMatomo(data.status === 'logged-in');
});
}
disconnectedCallback() {
this._bus.close();
super.disconnectedCallback();
}
render() {
return ``;
}
setupMatomo(loggedIn) {
if (loggedIn && ! this.isRunning) {
if (this.siteId === -1) {
console.log('site id missing, skipping matomo...');
return;
}
if (this.endpoint === '') {
console.log('endpoint missing, skipping matomo...');
return;
}
console.log('add matomo...');
window._paq = window._paq || [];
_paq.push(['setCustomVariable', 1, "GitCommit", buildInfo.info, "visit"]);
_paq.push(['enableHeartBeatTimer']);
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function (endpoint, siteId) {
_paq.push(['setTrackerUrl', endpoint+'matomo.php']);
_paq.push(['setSiteId', siteId]);
var g = document.createElement('script');
var s = document.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = endpoint + 'matomo.js';
s.parentNode.insertBefore(g, s);
})(this.endpoint, this.siteId);
// track changed locations
window.addEventListener('locationchanged', function(e) {
_paq.push(['setReferrerUrl', e.detail.referrerUrl]);
_paq.push(['setCustomUrl', location.href]);
// _paq.push(['setDocumentTitle', '']);
_paq.push(['trackPageView']);
// make Matomo aware of newly added content
var content = document.getElementById('content');
_paq.push(['MediaAnalytics::scanForMedia', content]);
_paq.push(['FormAnalytics::scanForForms', content]);
_paq.push(['trackContentImpressionsWithinNode', content]);
});
// track errors
window.addEventListener('error', function(e) {
_paq.push(['trackEvent', 'Error', e.error.message + '\n' + e.error.stack]);
});
this.isRunning = true;
if (this.lastEvent.length > 0) {
console.log('MatomoElement* (' + this.isRunning + '): ' + this.lastEvent[1] + ', ' + this.lastEvent[2]);
_paq.push(this.lastEvent);
this.lastEvent = [];
}
return;
}
if (! loggedIn && this.isRunning) {
// TODO: reomve those event listeners
console.log('remove matomo...');
this.isRunning = false;
}
}
track (action, message) {
console.log('MatomoElement (' + this.isRunning + '): ' + action + ', ' + message);
const event = ['trackEvent', action, message];
if (this.isRunning) {
_paq.push(event);
} else {
this.lastEvent = event;
}
}
}
describe('dbp-matomo', () => {
it('should render', () => {});
});
......@@ -1131,6 +1131,11 @@
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
"@types/ejs@^3.0.4":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@types/ejs/-/ejs-3.0.4.tgz#8851fcdedb96e410fbb24f83b8be6763ef9afa77"
integrity sha512-ZxnwyBGO4KX/82AsFHTX82eMw0PsoBcIngEat+zx0y+3yxoNDJucAihg9nAcrc+g4Cwiv/4WcWsX4oiy0ySrRQ==
"@types/estree@*":
version "0.0.45"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884"
......@@ -1577,6 +1582,11 @@ async-limiter@~1.0.0:
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==
async@0.9.x:
version "0.9.2"
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
integrity sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=
asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
......@@ -2996,6 +3006,13 @@ ee-first@1.1.1:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
ejs@^3.1.3:
version "3.1.5"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.5.tgz#aed723844dc20acb4b170cd9ab1017e476a0d93b"
integrity sha512-dldq3ZfFtgVTJMLjOe+/3sROTzALlL9E34V4/sDtUd/KlBSS0s6U1/+WPE1B4sj9CXHJpL1M6rhNJnc9Wbal9w==
dependencies:
jake "^10.6.1"
electron-to-chromium@^1.3.488:
version "1.3.498"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.498.tgz#fd7188c8a49d6d0b5df1df55a1f1a4bf2c177457"
......@@ -3449,7 +3466,7 @@ fast-glob@^2.2.6:
merge2 "^1.2.3"
micromatch "^3.1.10"
fast-glob@^3.0.3:
fast-glob@^3.0.3, fast-glob@^3.2.2:
version "3.2.4"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.4.tgz#d20aefbf99579383e7f3cc66529158c9b98554d3"
integrity sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ==
......@@ -3519,6 +3536,13 @@ file-saver@^2.0.2:
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.2.tgz#06d6e728a9ea2df2cce2f8d9e84dfcdc338ec17a"
integrity sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw==
filelist@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.1.tgz#f10d1a3ae86c1694808e8f20906f43d4c9132dbb"
integrity sha512-8zSK6Nu0DQIC08mUC46sWGXi+q3GGpKydAG36k+JDba6VRpkevvOWUW5a/PhShij4+vHT9M+ghgG7eM+a9JDUQ==
dependencies:
minimatch "^3.0.4"
fill-range@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7"
......@@ -4798,6 +4822,16 @@ iterate-value@^1.0.0:
es-get-iterator "^1.0.2"
iterate-iterator "^1.0.1"
jake@^10.6.1:
version "10.8.2"
resolved "https://registry.yarnpkg.com/jake/-/jake-10.8.2.tgz#ebc9de8558160a66d82d0eadc6a2e58fbc500a7b"
integrity sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==
dependencies:
async "0.9.x"
chalk "^2.4.2"
filelist "^1.0.1"
minimatch "^3.0.4"
jest-worker@^26.0.0:
version "26.1.0"
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.1.0.tgz#65d5641af74e08ccd561c240e7db61284f82f33d"
......@@ -7283,6 +7317,16 @@ rollup-plugin-delete@^2.0.0:
dependencies:
del "^5.1.0"
rollup-plugin-emit-ejs@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-emit-ejs/-/rollup-plugin-emit-ejs-3.1.0.tgz#abf8804db49368517dcc0e8531e7e811c5d8dc11"
integrity sha512-GZR68O+tubvVH23KIn4487exrev1ojioH+QnD+VfqJE/Yczsq79yiLO8jp4eg3SulSbXerofz/7DnLfowMLdDg==
dependencies:
"@types/ejs" "^3.0.4"
ejs "^3.1.3"
fast-glob "^3.2.2"
fs-extra "^8.1.0"
rollup-plugin-postcss@^3.1.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/rollup-plugin-postcss/-/rollup-plugin-postcss-3.1.3.tgz#b11f69a907cc497311f44da12030439545a7bd80"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment