Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Matomo #1041

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import remarkGfm from 'remark-gfm';
export default {
stories: [
'../docs/src/**/*.mdx',
'../oereb_client/**/*.stories.@(js|jsx|ts|tsx|mdx)',
'../oereb_client/**/*.@(mdx|stories.@(js|jsx|ts|tsx))',
],
addons: [
"@storybook/addon-links",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

https://github.com/openoereb/oereb_client/milestone/17

- Include Matomo JavaScript Client
- Dependency updates

2.1.3
Expand Down
6 changes: 6 additions & 0 deletions docs/src/Configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ oereb_client:
# parameter undefined to disable Google Analytics.
google_analytics: UA-12345678-9

# [OPTIONAL] Enable Matomo tracking by specifying matomo URL and site ID. Leave this
# parameter undefined to disable Matomo.
matomo:
url: https://matomo.example.com
id: 1

# [OPTIONAL] The mask_surrounding layer can be used to lay a mask (half-transparent
# white layer) on the surrounding cantons. You have to define a WMS URL and
# params according to the ol.source.ImageWMS documentation:
Expand Down
9 changes: 8 additions & 1 deletion oereb_client/static/src/component/app/app.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {isString} from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import React, {useEffect} from 'react';
import {useDispatch} from 'react-redux';

import {initAvailability, setAvailabilityPrefix} from '../../reducer/availability';
Expand All @@ -15,6 +15,7 @@ import OerebInformationPanel from '../information_panel/information_panel';
import OerebMap from '../map/map';
import OerebMenu from '../menu/menu';
import OerebMessage from '../message/message';
import MatomoTracker from '../matomo_tracker/matomo_tracker';

const App = function (props) {
const dispatch = useDispatch();
Expand Down Expand Up @@ -67,13 +68,19 @@ const App = function (props) {
});
}

let tracker = null;
if (config['matomo'] && config['matomo']['url'] && config['matomo']['site_id']) {
tracker = <MatomoTracker matomoUrl={config['matomo']['url']} siteId={config['matomo']['site_id']} />;
}

return (
<div className="oereb-client-app">
<OerebMap />
<OerebInformationPanel />
<OerebExtract />
<OerebMenu />
<OerebMessage />
{tracker}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import PropTypes from 'prop-types';
import React, {useEffect} from 'react';

const MatomoTracker = ({matomoUrl, siteId}) => {
useEffect(() => {
const script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.defer = true;
script.src = `${matomoUrl}/matomo.js`;
document.body.appendChild(script);
window._paq = window._paq || [];
window._paq.push(['trackPageView']);
window._paq.push(['enableLinkTracking']);
window._paq.push(['setTrackerUrl', `${matomoUrl}/matomo.php`]);
window._paq.push(['setSiteId', siteId]);
}, [matomoUrl, siteId]);
return null;
};

MatomoTracker.propTypes = {
matomoUrl: PropTypes.string.isRequired,
siteId: PropTypes.number.isRequired
};

export default MatomoTracker;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Meta} from '@storybook/blocks';

<Meta title="API Reference/Component/MatomoTracker" />

# App

A hidden component enabling user tracking using Matomo.

```jsx
<MatomoTracker matomoUrl={matomoUrl} siteId={siteId} />
```

### Parameters

| Param | Type | Description |
| --- | --- | --- |
| matomoUrl | <code>String</code> | The URL of the Matomo instance. |
| siteId | <code>Number</code> | The ID of the Site configured in Matomo. |
27 changes: 0 additions & 27 deletions oereb_client/static/src/reducer/accordion.mdx

This file was deleted.

35 changes: 0 additions & 35 deletions oereb_client/static/src/reducer/availability.mdx

This file was deleted.

17 changes: 0 additions & 17 deletions oereb_client/static/src/reducer/config.mdx

This file was deleted.

122 changes: 0 additions & 122 deletions oereb_client/static/src/reducer/extract.mdx

This file was deleted.

49 changes: 0 additions & 49 deletions oereb_client/static/src/reducer/history.mdx

This file was deleted.

Loading
Loading