Skip to content

Analytics: add feature flag to skip tracking 404s #9131

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

Merged
merged 3 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,7 @@ def add_features(sender, **kwargs):
LIMIT_CONCURRENT_BUILDS = "limit_concurrent_builds"
CDN_ENABLED = "cdn_enabled"
DOCKER_GVISOR_RUNTIME = "gvisor_runtime"
DONT_RECORD_404_PAGE_VIEWS = "dont_record_404_page_views"

# Versions sync related features
SKIP_SYNC_TAGS = 'skip_sync_tags'
Expand Down Expand Up @@ -1850,6 +1851,10 @@ def add_features(sender, **kwargs):
DOCKER_GVISOR_RUNTIME,
_("Use Docker gVisor runtime to create build container."),
),
(
DONT_RECORD_404_PAGE_VIEWS,
_("Don't record 404s page views."),
),

# Versions sync related features
(
Expand Down
17 changes: 11 additions & 6 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
Domain,
EmailHook,
EnvironmentVariable,
Feature,
Project,
ProjectRelationship,
WebHook,
Expand Down Expand Up @@ -1180,12 +1181,15 @@ def get_context_data(self, **kwargs):

# Count of views for top pages over the month
top_pages_200 = PageView.top_viewed_pages(project, limit=25)
top_pages_404 = PageView.top_viewed_pages(
project,
limit=25,
status=404,
per_version=True,
)
track_404 = not project.has_feature(Feature.DONT_RECORD_404_PAGE_VIEWS)
top_pages_404 = []
if track_404:
top_pages_404 = PageView.top_viewed_pages(
project,
limit=25,
status=404,
per_version=True,
)

# Aggregate pageviews grouped by day
page_data = PageView.page_views_by_date(
Expand All @@ -1197,6 +1201,7 @@ def get_context_data(self, **kwargs):
"top_pages_200": top_pages_200,
"page_data": page_data,
"top_pages_404": top_pages_404,
"track_404": track_404,
}
)

Expand Down
4 changes: 4 additions & 0 deletions readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from readthedocs.core.utils.extend import SettingsOverrideObject
from readthedocs.projects import constants
from readthedocs.projects.constants import SPHINX_HTMLDIR
from readthedocs.projects.models import Feature
from readthedocs.projects.templatetags.projects_tags import sort_version_aware
from readthedocs.redirects.exceptions import InfiniteRedirectException
from readthedocs.storage import build_media_storage
Expand Down Expand Up @@ -402,6 +403,9 @@ def get(self, request, proxito_path, template_name='404.html'):

def _register_broken_link(self, project, version, path, full_path):
try:
if project.has_feature(Feature.DONT_RECORD_404_PAGE_VIEWS):
return

# If the path isn't attached to a version
# it should be the same as the full_path,
# otherwise it would be empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h3>{% trans "Daily pageview totals" %}</h3>
<button type="submit" name="download" value="true">{% trans "Download all data" %}</button>
</form>

{% if track_404 %}
<h3>{% trans "Not Found (404) pages" %}</h3>

<div class="module-list">
Expand Down Expand Up @@ -76,7 +77,7 @@ <h3>{% trans "Not Found (404) pages" %}</h3>
It's possible the number of times each page is viewed is undercounted because of caching in the browser or in a CDN.
{% endblocktrans %}
</small>

{% endif %}

{% endblock %}

Expand Down