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

Matomo track phase2 #6387

Open
wants to merge 4 commits into
base: dev
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
4 changes: 2 additions & 2 deletions templates/tutorialv2/contributions.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 class="ico-after ico-contribution_tutorials">
</h2>
<div class="content-item-list clearfix">
{% for contribution_tutorial in contribution_tutorials %}
{% include "tutorialv2/includes/content_item.part.html" with show_description=True public_content=contribution_tutorial.public_version content=contribution_tutorial%}
{% include "tutorialv2/includes/content_item.part.html" with show_description=True public_content=contribution_tutorial.public_version content=contribution_tutorial source="&src=contributor"%}
{% endfor %}
<div class="fill"></div>
<div class="fill"></div>
Expand All @@ -63,7 +63,7 @@ <h2 class="ico-after ico-contribution_tutorials">
</h2>
<div class="content-item-list clearfix">
{% for contribution_article in contribution_articles %}
{% include "tutorialv2/includes/content_item.part.html" with show_description=True public_content=contribution_article.public_version content=contribution_article show_reactions=True %}
{% include "tutorialv2/includes/content_item.part.html" with show_description=True public_content=contribution_article.public_version content=contribution_article show_reactions=True source="&src=contributor" %}
{% endfor %}
<div class="fill"></div>
<div class="fill"></div>
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorialv2/includes/content_item.part.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<div class="content-info">
<header>
<h3 class="content-title" itemprop="itemListElement">
<a href="{{ link }}" title="{{ content_title }}{% if content_subtitle and show_description %} − {{ content_subtitle }}{% endif %}">
<a href="{{ link }}{{ source }}" title="{{ content_title }}{% if content_subtitle and show_description %} − {{ content_subtitle }}{% endif %}">
{{ content_title }}
</a>
</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorialv2/includes/content_suggestion.part.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h2>Ces contenus pourraient vous intéresser</h2>
<div class="content-item-list">
{% for content_suggestion in content_suggestions %}
{% include "tutorialv2/includes/content_item.part.html" with public_content=content_suggestion.suggestion.public_version show_description=True show_reactions=True %}
{% include "tutorialv2/includes/content_item.part.html" with public_content=content_suggestion.suggestion.public_version show_description=True show_reactions=True source="&src=suggestion" %}
{% endfor %}
{% for i in col_number|times %}
<div class="fill"></div>
Expand Down
13 changes: 12 additions & 1 deletion zds/middlewares/matomomiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
tracked_status_code = [200]
tracked_methods = ["GET"]
excluded_paths = ["/contenus", "/mp", "/munin", "/api", "/static", "/media"]
# we track only public download
download_paths = ["/pdf/", "/epub/"]
content_elements = ["tutoriels", "articles", "billets"]


def _background_process(queue: Queue):
Expand All @@ -37,7 +40,14 @@ def _background_process(queue: Queue):
"m": data["datetime"].minute,
"s": data["datetime"].second,
}
if "search" in data:
if any(part in data["client_url"] for part in download_paths):
params["download"] = data["client_url"]
elif any("/" + part + "/" in data["client_url"] for part in content_elements) and "src" in data["get_params"]:
params["e_c"] = data["get_params"]["src"]
params["e_a"] = "clicked"
params["e_n"] = list("/" + part + "/" in data["client_url"] for part in content_elements)[0]
params["e_v"] = 1
elif "search" in data:
params["search"] = data["search"]
params["search_cat"] = data["search_cat"]
params["search_count"] = data["search_count"]
Expand Down Expand Up @@ -90,6 +100,7 @@ def matomo_track(self, request, search_data=None):
"datetime": datetime.now().time(),
"r_path": request.path,
"address_ip": get_client_ip(request),
"get_params": dict(**requests.GET),
}
if search_data:
tracking_params.update(search_data)
Expand Down