Skip to content

Commit acaa0f6

Browse files
committed
Include matomo tracker
1 parent 6ff7237 commit acaa0f6

File tree

6 files changed

+118
-4
lines changed

6 files changed

+118
-4
lines changed

core/settings/project.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@
212212

213213
NOMINATIM_API_URL = os.getenv('NOMINATIM_API_URL', 'https://nominatim.openstreetmap.org/search.php')
214214

215+
MATOMO_URL = os.getenv('MATOMO_URL')
216+
MATOMO_SITEID = os.getenv('MATOMO_SITEID')
217+
215218
HDX_URL_PREFIX = Configuration.create(
216219
hdx_site=os.getenv('HDX_SITE', 'demo'),
217220
hdx_key=os.getenv('HDX_API_KEY'),

ui/app/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Help from "./components/Help";
2424
import Home from "./components/Home";
2525
import NavBar from "./components/NavBar";
2626
import Stats from "./components/Stats";
27+
import Banner from "./components/Banner";
2728
import { requireAuth } from "./components/utils";
2829

2930
import "@blueprintjs/core/dist/blueprint.css";
@@ -42,13 +43,13 @@ addLocaleData([...de, ...en, ...es, ...fr, ...id, ...it, ...pt, ...nl]);
4243
FocusStyleManager.onlyShowFocusOnTabs();
4344

4445
export default ({ history }) => {
45-
4646
return (
4747
<IntlProvider>
4848
<ConnectedRouter history={history}>
4949
<div style={{ height: "100%" }}>
5050
<Auth />
5151
<NavBar />
52+
<Banner />
5253
<Switch>
5354
<Route path="/authorized" component={Authorized} />
5455
<Route path="/configurations" component={Configurations} />

ui/app/components/Banner.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, { Component } from "react";
2+
import { FormattedMessage } from "react-intl";
3+
4+
class Banner extends Component {
5+
state = {
6+
consent: localStorage.getItem("accept-consent", undefined),
7+
};
8+
9+
Close = (accept) => {
10+
localStorage.setItem("accept-consent", accept);
11+
this.setState({ consent: accept });
12+
13+
let event = "forgetConsentGiven";
14+
if (accept === true) {
15+
event = "rememberConsentGiven";
16+
}
17+
18+
// _paq object belongs to Matomo. Check v3.html page.
19+
window._paq.push([event]);
20+
};
21+
22+
render() {
23+
if (this.state.consent) {
24+
return null;
25+
}
26+
27+
return (
28+
<div className="banner">
29+
<h2>
30+
<FormattedMessage
31+
id="ui.banner.title"
32+
defaultMessage="About the information we collect"
33+
/>
34+
</h2>
35+
36+
<p>
37+
<FormattedMessage
38+
id="ui.banner.message"
39+
defaultMessage="We use cookies and similar technologies to recognize and analyze your visits, and measure traffic usage and activity. You can learn about how we use the data about your visit or information you provide reading our {policyLink}. By clicking I Agree , you consent to the use of cookies."
40+
values={{
41+
policyLink: (
42+
<a
43+
href="https://hotosm.org/privacy"
44+
className="red underline link fw6"
45+
target="_blank"
46+
rel="noopener noreferrer"
47+
>
48+
privacy policy
49+
</a>
50+
),
51+
}}
52+
/>
53+
</p>
54+
<div className="banner-wrapper">
55+
<button onClick={() => this.Close(false)}>
56+
<FormattedMessage
57+
id="ui.banner.not_agree"
58+
defaultMessage="I do not agree"
59+
/>
60+
</button>
61+
<button onClick={() => this.Close(true)}>
62+
<FormattedMessage id="ui.banner.agree" defaultMessage="I agree" />
63+
</button>
64+
</div>
65+
</div>
66+
);
67+
}
68+
}
69+
70+
export default Banner;

ui/app/css/style.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,3 +1428,23 @@ p {
14281428
background-color: white;
14291429
z-index: 100;
14301430
}
1431+
1432+
.banner {
1433+
width: 100vw;
1434+
padding: 2rem;
1435+
text-align: center;
1436+
position: fixed;
1437+
z-index: 99;
1438+
bottom: 0;
1439+
background-color: #fff;
1440+
border-top: 1px solid gray;
1441+
}
1442+
1443+
.banner-wrapper {
1444+
display: flex;
1445+
width: 14%;
1446+
margin-left: auto;
1447+
margin-right: auto;
1448+
justify-content: space-between;
1449+
}
1450+

ui/templates/ui/v3.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
<title>HOT Export Tool</title>
99
<link href='//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,300,700' rel='stylesheet' type='text/css'>
1010
<link rel="icon" href="{% static 'ui/images/favicon.ico' %}">
11+
{% if MATOMO_URL and MATOMO_SITEID %}
12+
<script type="text/javascript">
13+
var _paq = window._paq = window._paq || [];
14+
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
15+
_paq.push(['trackPageView']);
16+
_paq.push(['enableLinkTracking']);
17+
(function() {
18+
var u='{{ MATOMO_URL }}';
19+
_paq.push(['setTrackerUrl', u+'piwik.php']);
20+
_paq.push(['setSiteId', '{{ MATOMO_SITEID }}']);
21+
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
22+
g.type='text/javascript'; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
23+
})();
24+
</script>
25+
{% endif %}
1126
</head>
1227
<body>
1328
<div id="root" class="container-fluid" style="height:calc(100% - 105px)"></div>

ui/views.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from oauth2_provider.models import Application
99
from django.contrib import admin
1010
from django.contrib.auth.admin import User, UserAdmin
11+
from django.conf import settings
1112

1213
def authorized(request):
1314
# the user has now authorized a client application; they no longer need to
@@ -36,9 +37,13 @@ def logout(request):
3637
def v3(request):
3738
ui_app = Application.objects.get(name='OSM Export Tool UI')
3839

39-
return render(request, 'ui/v3.html', {
40-
'client_id': ui_app.client_id
41-
})
40+
context = dict(client_id=ui_app.client_id)
41+
if settings.MATOMO_URL is not None and settings.MATOMO_SITEID is not None:
42+
context.update({
43+
'MATOMO_URL': settings.MATOMO_URL,
44+
'MATOMO_SITEID': settings.MATOMO_SITEID
45+
})
46+
return render(request, 'ui/v3.html', context)
4247

4348

4449
def redirect_to_v3(request):

0 commit comments

Comments
 (0)