File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,8 @@ def _(x):
211
211
# Google
212
212
# =======================
213
213
# THEME_GOOGLE_SITE_VERIFICATION = []
214
+ # Example of id: UA-XXXXXX-XX
215
+ # RERO_ILS_GOOGLE_ANALYTICS_TAG_ID =
214
216
215
217
# Miscellaneous variable around templates
216
218
# =======================
Original file line number Diff line number Diff line change 1
1
<!--
2
2
3
3
RERO ILS
4
- Copyright (C) 2019 RERO
4
+ Copyright (C) 2019-2024 RERO
5
5
6
6
This program is free software: you can redistribute it and/or modify
7
7
it under the terms of the GNU Affero General Public License as published by
16
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
18
18
-->
19
+ {% if config.get('RERO_ILS_GOOGLE_ANALYTICS_TAG_ID') %}
19
20
<!-- Global site tag (gtag.js) - Google Analytics -->
20
- < script async src ="https://www.googletagmanager.com/gtag/js?id=UA-1831395-14 "> </ script >
21
+
22
+ {% set TAG_ID = config.get('RERO_ILS_GOOGLE_ANALYTICS_TAG_ID') %}
23
+ < script async src ="https://www.googletagmanager.com/gtag/js?id={{ TAG_ID }} "> </ script >
21
24
< script >
22
25
window . dataLayer = window . dataLayer || [ ] ;
23
26
function gtag ( ) { dataLayer . push ( arguments ) ; }
24
27
gtag ( 'js' , new Date ( ) ) ;
25
28
26
- gtag ( 'config' , 'UA-1831395-14 ' ) ;
29
+ gtag ( 'config' , '{{ TAG_ID }} ' ) ;
27
30
</ script >
31
+
32
+ {% endif %}
Original file line number Diff line number Diff line change @@ -205,3 +205,15 @@ def test_set_user_name(
205
205
login_user (user = librarian_martigny .user )
206
206
assert session ['user_name' ] == librarian_martigny .formatted_name
207
207
logout_user ()
208
+
209
+
210
+ def test_google_analytics (client , app ):
211
+ """Testing the insertion of the google analytics code in the html page."""
212
+ # The Google Analytics code must not be present on the page.
213
+ result = client .get (url_for ('rero_ils.index' ))
214
+ assert 'gtag' not in result .text
215
+
216
+ # The Google Analytics code must be present on the page.
217
+ app .config ['RERO_ILS_GOOGLE_ANALYTICS_TAG_ID' ] = 'GA-Foo'
218
+ result = client .get (url_for ('rero_ils.index' ))
219
+ assert 'gtag' in result .text
You can’t perform that action at this time.
0 commit comments