Skip to content

Commit

Permalink
Merge pull request #606 from mlibrary/fixup/ga-limits
Browse files Browse the repository at this point in the history
We're hitting GA quota limits on monograph_catalog pages.
  • Loading branch information
sethaj authored Nov 17, 2016
2 parents 02f77a6 + 05f7f7c commit 1a2e6ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 16 additions & 5 deletions app/presenters/concerns/analytics_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ def pageviews_by_path(path)
count = 0
profile = google_analytics_profile
if profile.present?
Pageview.results(profile).each do |entry|
count += entry[:pageviews].to_i if entry[:pagePath] == path
begin
Pageview.results(profile).each do |entry|
count += entry[:pageviews].to_i if entry[:pagePath] == path
end
rescue OAuth2::Error => e
Rails.logger.error(e.code["message"])
end
end
return count
Expand All @@ -16,10 +20,17 @@ def pageviews_by_ids(ids)
count = 0
profile = google_analytics_profile
if profile.present?
Pageview.results(profile).each do |entry|
ids.each do |id|
count += entry[:pageviews].to_i if entry[:pagePath].include? id
begin
Pageview.results(profile).each do |entry|
ids.each do |id|
count += entry[:pageviews].to_i if entry[:pagePath].include? id
end
end
rescue OAuth2::Error => e
# TODO: we're hitting GA quotas for monograph_catalog pages in production.
# Need to figure out a better way to do this...
Rails.logger.error(e.code["message"])
return nil
end
end
return count
Expand Down
5 changes: 4 additions & 1 deletion app/views/monograph_catalog/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
<div class="description">
<%= render_markdown @monograph_presenter.description.first || '' %>
</div>
<% pageviews = @monograph_presenter.pageviews %>
<% unless pageviews.nil? %>
<div>
<p>This item has been viewed <b><%= @monograph_presenter.pageviews %></b> times.</p>
<p>This item has been viewed <b><%= pageviews %></b> times.</p>
</div>
<% end %>
<div><p></p></div>
<div class="isbn">
<% if defined?(@monograph_presenter.isbn) %>
Expand Down

0 comments on commit 1a2e6ab

Please sign in to comment.