Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #73 from alphagov/remove-other-result-from-popular…
Browse files Browse the repository at this point in the history
…-content

Remove '(other)' results from API response
  • Loading branch information
Rosa-Fox authored Nov 17, 2022
2 parents fcdf2ec + 4767f79 commit b478720
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,30 @@ def most_popular_govuk_pages
else
formatted = []
rows.each do |row|
row_data = {
page_views: format_page_views_with_commas(row.dig(:metric_values).first.dig(:value)),
page_path: row.dig(:dimension_values).first.dig(:value),
page_title: row.dig(:dimension_values)[1].dig(:value)
}
formatted << row_data
page_title = row.dig(:dimension_values)[1].dig(:value)
unless other_result(page_title)
row_data = {
page_views: format_page_views_with_commas(row.dig(:metric_values).first.dig(:value)),
page_path: row.dig(:dimension_values).first.dig(:value),
page_title: page_title
}
formatted << row_data
end
end
formatted.to_json
end
end

private

def other_result(page_title)
#Sometimes the API returns '(other)' results which skew the data:
#https://support.google.com/analytics/answer/9309767#zippy=%2Cin-this-article.
#It doesn't look like we can eliminate them using the API query itself.
#There are only max 10 results, so a Ruby check has been added to eliminate (other) results.
page_title == "(other)"
end

def request
::Google::Analytics::Data::V1beta::RunReportRequest.new({
property: "properties/330577055",
Expand Down

0 comments on commit b478720

Please sign in to comment.