Skip to content

Commit 05f7f7c

Browse files
committed
We're hitting GA quota limits on monograph_catalog pages.
Should have seen this coming. We need to come up with a way to cache GA pageview (and other) stats.
1 parent 02f77a6 commit 05f7f7c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

app/presenters/concerns/analytics_presenter.rb

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ def pageviews_by_path(path)
55
count = 0
66
profile = google_analytics_profile
77
if profile.present?
8-
Pageview.results(profile).each do |entry|
9-
count += entry[:pageviews].to_i if entry[:pagePath] == path
8+
begin
9+
Pageview.results(profile).each do |entry|
10+
count += entry[:pageviews].to_i if entry[:pagePath] == path
11+
end
12+
rescue OAuth2::Error => e
13+
Rails.logger.error(e.code["message"])
1014
end
1115
end
1216
return count
@@ -16,10 +20,17 @@ def pageviews_by_ids(ids)
1620
count = 0
1721
profile = google_analytics_profile
1822
if profile.present?
19-
Pageview.results(profile).each do |entry|
20-
ids.each do |id|
21-
count += entry[:pageviews].to_i if entry[:pagePath].include? id
23+
begin
24+
Pageview.results(profile).each do |entry|
25+
ids.each do |id|
26+
count += entry[:pageviews].to_i if entry[:pagePath].include? id
27+
end
2228
end
29+
rescue OAuth2::Error => e
30+
# TODO: we're hitting GA quotas for monograph_catalog pages in production.
31+
# Need to figure out a better way to do this...
32+
Rails.logger.error(e.code["message"])
33+
return nil
2334
end
2435
end
2536
return count

app/views/monograph_catalog/index.html.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
<div class="description">
3030
<%= render_markdown @monograph_presenter.description.first || '' %>
3131
</div>
32+
<% pageviews = @monograph_presenter.pageviews %>
33+
<% unless pageviews.nil? %>
3234
<div>
33-
<p>This item has been viewed <b><%= @monograph_presenter.pageviews %></b> times.</p>
35+
<p>This item has been viewed <b><%= pageviews %></b> times.</p>
3436
</div>
37+
<% end %>
3538
<div><p></p></div>
3639
<div class="isbn">
3740
<% if defined?(@monograph_presenter.isbn) %>

0 commit comments

Comments
 (0)