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 matomo metrics in base template #1452

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ If you wish to make use of [intercom.io](https://www.intercom.io), include a
`private.py` file in `core.settings` with your `INTERCOM_APP_ID` as a string.
The necessary code snippet is already included in `project_base.html`.

**matomo.org**

If you wish to make use of [matomo.org](https://www.matomo.org), include a
`private.py` file in `core.settings` with your `MATOMO_SITE_ID` and `MATOMO_URL` as a string.
The necessary code snippet is already included in `project_base.html`.


**google authentication**

In social auth to use the google authentication you need to go to:
Expand Down
19 changes: 18 additions & 1 deletion django_project/core/base_templates/project_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,24 @@
<script src="https://cdn.rawgit.com/leafo/sticky-kit/v1.1.2/jquery.sticky-kit.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>


{% if matomo_url and matomo_site_id %}
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="{{ matomo_url }}";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', "{{ matomo_site_id }}"]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
{% endif %}

<!-- Chosen library -->
<link rel="stylesheet" href="{% static 'chosen/chosen.min.css' %}">
<script src="{% static 'chosen/chosen.jquery.min.js' %}"></script>
Expand Down
21 changes: 21 additions & 0 deletions django_project/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ def add_intercom_app_id(request):
else:
return {}

# noinspection PyPep8Naming
def add_matomo_variables(request):
"""Add our matomo vars to the context

:param request: Http Request obj

"""
try:
from core.settings.private import MATOMO_SITE_ID
from core.settings.private import MATOMO_URL
except ImportError:
MATOMO_SITE_ID = None
MATOMO_URL = None

if MATOMO_SITE_ID and MATOMO_URL:
return {'matomo_site_id': MATOMO_SITE_ID, 'matomo_url': MATOMO_URL}
else:
return {}




def stripe_public_key(request):
"""Return stripe public key.
Expand Down
1 change: 1 addition & 0 deletions django_project/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
# Already defined Django-related contexts
'django.contrib.auth.context_processors.auth',
'core.context_processors.add_intercom_app_id',
'core.context_processors.add_matomo_variables',
'core.context_processors.stripe_public_key',
'core.context_processors.sustaining_member_context',
'django.template.context_processors.i18n',
Expand Down