Skip to content

Commit d13423d

Browse files
committed
Fix analytics, loading of file URLs
1 parent e469bf7 commit d13423d

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

app/controllers/yard_controller.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,13 @@ def respond
7474
expires_in 1.day, public: true
7575
end
7676

77-
if use_template?
77+
if status == 200 && Mime::Type.lookup(headers["Content-Type"]).html?
7878
render :show
7979
else
8080
render plain: body.first, status: status, headers: headers, content_type: headers["Content-Type"]
8181
end
8282
end
8383

84-
def use_template?
85-
return false if status != 200
86-
return false if %w[/search /static].any? { |path| request.path.starts_with?(path) }
87-
return false if params[:rest].to_s.starts_with?("file/")
88-
true
89-
end
90-
9184
def visit_library
9285
FileUtils.touch(library_version.source_path)
9386
end

app/views/layouts/_analytics.html.erb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@
1212
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= Rubydoc.config.integrations.google_analytics %>"></script>
1313
<script>
1414
window.dataLayer = window.dataLayer || [];
15-
function gtag(){dataLayer.push(arguments);}
16-
gtag('consent', 'update', {
15+
if (window.gtag) {
16+
gtag('event', 'page_view', {
17+
page_title: document.title,
18+
page_location: window.location.href,
19+
});
20+
} else {
21+
function gtag(){dataLayer.push(arguments);}
22+
gtag('consent', 'update', {
1723
'ad_user_data': 'denied',
1824
'ad_personalization': 'denied',
1925
'ad_storage': 'denied',
2026
'analytics_storage': 'denied'
21-
});
22-
gtag('js', new Date());
23-
24-
gtag('config', '<%= Rubydoc.config.integrations.google_analytics %>');
27+
});
28+
gtag('js', new Date());
29+
gtag('config', '<%= Rubydoc.config.integrations.google_analytics %>');
30+
}
2531
</script>
2632
<% end %>

0 commit comments

Comments
 (0)