Skip to content

Commit

Permalink
Merge pull request #6057 from escattone/fix-weekly-pageview-crons-1819
Browse files Browse the repository at this point in the history
fix article & question weekly pageview crons
  • Loading branch information
escattone committed Jun 11, 2024
2 parents 715338d + eaad0eb commit 9010c23
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
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

0 comments on commit 9010c23

Please sign in to comment.