Skip to content
Snippets Groups Projects
Commit 40e5c129 authored by Neuber, Eugen Ramon's avatar Neuber, Eugen Ramon :speech_balloon:
Browse files

Add Matomo config to dem attributes

See issue #29
parent a8c45057
No related branches found
No related tags found
1 merge request!2Matomo web component
Pipeline #12996 failed
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
......@@ -7,7 +7,9 @@
<body>
<dbp-matomo-demo lang="de"></dbp-matomo-demo>
<dbp-matomo-demo lang="de" matomo-url="<%= matomoUrl %>" matomo-site-id="<%= matomoSiteId %>"></dbp-matomo-demo>
<p>version: <span style="color: white; background-color: black;"><%= buildInfo.info %></span></p>
<p>Matomo: url: <%= matomoUrl %>, site-id: <%= matomoSiteId %></p>
</body>
</html>
......@@ -8,10 +8,38 @@ import serve from 'rollup-plugin-serve';
import url from "@rollup/plugin-url";
import consts from 'rollup-plugin-consts';
import del from 'rollup-plugin-delete';
import emitEJS from 'rollup-plugin-emit-ejs'
import {getPackagePath} from '../../rollup.utils.js';
const pkg = require('./package.json');
const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local';
console.log("build: " + build);
const matomoUrl = "https://analytics.tugraz.at/";
const matomoSiteId = 131;
function getBuildInfo() {
const child_process = require('child_process');
const url = require('url');
let remote = child_process.execSync('git config --get remote.origin.url').toString().trim();
let commit = child_process.execSync('git rev-parse --short HEAD').toString().trim();
let parsed = url.parse(remote);
// convert git urls
if (parsed.protocol === null) {
parsed = url.parse('git://' + remote.replace(":", "/"));
parsed.protocol = 'https:';
}
let newPath = parsed.path.slice(0, parsed.path.lastIndexOf('.'));
let newUrl = parsed.protocol + '//' + parsed.host + newPath + '/commit/' + commit;
return {
info: commit,
url: newUrl,
time: new Date().toISOString(),
env: build
}
}
export default (async () => {
return {
......@@ -37,6 +65,23 @@ export default (async () => {
consts({
environment: build,
}),
emitEJS({
src: 'assets',
include: ['**/*.ejs', '**/.*.ejs'],
data: {
getUrl: (p) => {
return url.resolve(basePath, p);
},
getPrivateUrl: (p) => {
return url.resolve(`${basePath}local/${pkg.name}/`, p);
},
name: pkg.name,
environment: build,
matomoUrl: matomoUrl,
matomoSiteId: matomoSiteId,
buildInfo: getBuildInfo()
}
}),
resolve(),
commonjs(),
url({
......
......@@ -12,6 +12,8 @@ class MatomoDemo extends ScopedElementsMixin(LitElement) {
constructor() {
super();
this.lang = 'de';
this.matomoUrl = '';
this.matomoSiteId = -1;
}
static get scopedElements() {
......@@ -25,6 +27,8 @@ class MatomoDemo extends ScopedElementsMixin(LitElement) {
static get properties() {
return {
lang: { type: String },
matomoUrl: { type: String, attribute: "matomo-url" },
matomoSiteId: { type: Number, attribute: "matomo-site-id" },
};
}
......@@ -67,7 +71,7 @@ class MatomoDemo extends ScopedElementsMixin(LitElement) {
<div class="container">
<dbp-auth-keycloak lang="${this.lang}" url="https://auth-dev.tugraz.at/auth" realm="tugraz" client-id="auth-dev-mw-frontend-local" load-person try-login></dbp-auth-keycloak>
<dbp-login-button lang="${this.lang}" show-image></dbp-login-button>
<dbp-matomo endpoint="https://analytics.tugraz.at/" site-id="131"></dbp-matomo>
<dbp-matomo endpoint="${this.matomoUrl}" site-id="${this.matomoSiteId}"></dbp-matomo>
</div>
<div class="container">
<p>Click this button (and watch the network traffic) ...</p>
......
......@@ -40,9 +40,6 @@ export class MatomoElement extends DBPLitElement {
}
setupMatomo(loggedIn) {
console.log('setupMatomo: loggedIn = ' + loggedIn);
console.log('setupMatomo: running = ' + this.isRunning);
if (loggedIn && ! this.isRunning) {
console.log('add matomo...');
......@@ -96,7 +93,7 @@ export class MatomoElement extends DBPLitElement {
}
track (action, message) {
console.log('MatomoElement (' +this.isRunning+'): ' + action + ', ' + message);
console.log('MatomoElement (' + this.isRunning + '): ' + action + ', ' + message);
if (this.isRunning) {
_paq.push(['trackEvent', action, message]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment