Matomo Web Component
You can install this component via npm:
npm i @dbp-toolkit/matomo
Usage
<dbp-matomo></dbp-matomo>
<script type="module" src="node_modules/@dbp-toolkit/matomo/dist/dbp-matomo.js"></script>
Attributes
endpoint
(required): set to your Matomo server
- example
<dbp-matomo endpoint="https://my-matomo.tld"></dbp-matomo>
site-id
(required): set to your site id
- example
<dbp-matomo site-id="456789"></dbp-matomo>
Tracking actions
class Demo {
track(action, message) {
const matomo = this.shadowRoot.querySelector(this.constructor.getScopedTagName('dbp-matomo'));
if (matomo !== null) {
matomo.track(action, message);
}
}
clickMe() {
this.track('button clicked', 'alert()');
}
}
Local development
git clone git@gitlab.tugraz.at:dbp/web-components/toolkit.git
cd toolkit/packages/matomo
yarn install
yarn run watch
yarn test
yarn run build
Jump to http://localhost:8002 and you should get a demo page.