File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,12 @@ def pageviews_by_path(path)
5
5
count = 0
6
6
profile = google_analytics_profile
7
7
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" ] )
10
14
end
11
15
end
12
16
return count
@@ -16,10 +20,17 @@ def pageviews_by_ids(ids)
16
20
count = 0
17
21
profile = google_analytics_profile
18
22
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
22
28
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
23
34
end
24
35
end
25
36
return count
Original file line number Diff line number Diff line change 29
29
< div class ="description ">
30
30
<%= render_markdown @monograph_presenter . description . first || '' %>
31
31
</ div >
32
+ <% pageviews = @monograph_presenter . pageviews %>
33
+ <% unless pageviews . nil? %>
32
34
< 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 >
34
36
</ div >
37
+ <% end %>
35
38
< div > < p > </ p > </ div >
36
39
< div class ="isbn ">
37
40
<% if defined? ( @monograph_presenter . isbn ) %>
You can’t perform that action at this time.
0 commit comments