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

fix article & question weekly pageview crons #6057

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions kitsune/sumo/googleanalytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,16 @@ def pageviews_by_document(period, verbose=False):

for row in run_report(date_range, create_article_report_request, verbose=verbose):
path = row.dimension_values[0].value
num_page_views = int(row.metric_values[0].value)
# The path is guaranteed to be a KB article path without any query parameters.
# If the URL path for KB articles changes, we'll need to continue to support
# the previous URL structure for a year -- the longest period of time we look
# backwards -- as well as the new URL structure.
# The path should be a KB article path without any query parameters, but in reality
# we've seen that it can sometimes be "/". If the URL path for KB articles changes,
# we'll need to continue to support the previous URL structure for a year -- the
# longest period of time we look backwards -- as well as the new URL structure.
# Current URL structure: /{locale}/kb/{slug}
locale, slug = path.strip("/").split("/kb/")
try:
num_page_views = int(row.metric_values[0].value)
locale, slug = path.strip("/").split("/kb/")
except ValueError:
continue
yield ((locale, slug), num_page_views)


Expand All @@ -307,14 +310,18 @@ def pageviews_by_question(period=LAST_YEAR, verbose=False):

for row in run_report(date_range, create_question_report_request, verbose=verbose):
path = row.dimension_values[0].value
num_page_views = int(row.metric_values[0].value)
# The path is guaranteed to be a question path without any query parameters.
# If the URL path for questions changes, we'll need to continue to support
# the previous URL structure for a year -- the longest period of time we look
# backwards -- as well as the new URL structure.
# The path should be a question path without any query parameters, but in reality
# we've seen that it can sometimes be "/". If the URL path for questions changes,
# we'll need to continue to support the previous URL structure for a year -- the
# longest period of time we look backwards -- as well as the new URL structure.
# Current URL structure: /{locale}/questions/{question_id}
locale, question_id = path.strip("/").split("/questions/")
yield (int(question_id), num_page_views)
try:
num_page_views = int(row.metric_values[0].value)
locale, question_id = path.strip("/").split("/questions/")
question_id = int(question_id)
except ValueError:
continue
yield (question_id, num_page_views)


def search_clicks_and_impressions(start_date, end_date, verbose=False):
Expand Down
8 changes: 8 additions & 0 deletions kitsune/sumo/tests/test_googleanalytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def test_pageviews_by_document(self, run_report):
dimension_values=[DimensionValue(value="/en-US/kb/doc1-slug")],
metric_values=[MetricValue(value="1000")],
),
Row(
dimension_values=[DimensionValue(value="/")],
metric_values=[MetricValue(value="7")],
),
Row(
dimension_values=[DimensionValue(value="/es/kb/doc2-slug")],
metric_values=[MetricValue(value="2000")],
Expand All @@ -97,6 +101,10 @@ def test_pageviews_by_question(self, run_report):
dimension_values=[DimensionValue(value="/en-US/questions/123456")],
metric_values=[MetricValue(value="1000")],
),
Row(
dimension_values=[DimensionValue(value="/")],
metric_values=[MetricValue(value="7")],
),
Row(
dimension_values=[DimensionValue(value="/es/questions/782348")],
metric_values=[MetricValue(value="2000")],
Expand Down