Skip to content

Commit

Permalink
Add Google Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
marlo-longley authored and thatbudakguy committed Jan 5, 2023
1 parent 212320a commit 14754c1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/components/top_bar_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div data-controller="feedback">
<div data-controller="feedback analytics">
<nav class="navbar navbar-expand-md navbar-dark bg-dark topbar" role="navigation">
<div class="<%= container_classes %>">
<%= logo_link %>
Expand Down Expand Up @@ -49,4 +49,4 @@
</div>
</div>
</div>
</div>
</div>
11 changes: 11 additions & 0 deletions app/javascript/controllers/analytics_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
connect() {
const debug = Boolean(document.head.querySelector("meta[name=analytics_debug]").getAttribute("value"))
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-48Y3Q1L4K0', {'debug_mode': debug});
}
}
16 changes: 0 additions & 16 deletions app/views/layouts/application.html.erb

This file was deleted.

23 changes: 23 additions & 0 deletions app/views/layouts/blacklight.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- This file copies the equivalent file in Blacklight and adds VT Google Analytics in :head -->
<% content_for(:head) do %>
<%= render 'shared/analytics' %>
<% end %>

<% content_for(:content) do %>
<% if content_for? :sidebar %>
<section id="content" class="<%= main_content_classes %> order-last" aria-label="<%= t('blacklight.search.documents.aria.search_results') %>">
<%= yield %>
</section>

<section id="sidebar" class="<%= sidebar_classes %> order-first" aria-label="<%= t('blacklight.search.documents.aria.limit_search') %>">
<%= content_for(:sidebar) %>
</section>
<% else %>
<section class="col-md-12">
<%= yield %>
</section>
<% end %>
<% end %>

<%= render template: "layouts/blacklight/base" %>

16 changes: 16 additions & 0 deletions app/views/layouts/catalog_result.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- This file copies the equivalent file in Blacklight and adds VT Google Analytics in :head -->
<% content_for(:head) do %>
<%= render 'shared/analytics' %>
<% end %>

<% content_for(:content) do %>
<section class="<%= show_content_classes %>">
<%= yield %>
</section>

<section class="<%= show_sidebar_classes %>">
<%= content_for(:sidebar) %>
</section>
<% end %>

<%= render template: "layouts/blacklight/base" %>
2 changes: 2 additions & 0 deletions app/views/shared/_analytics.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script async src="https://www.googletagmanager.com/gtag/js?id=G-48Y3Q1L4K0"></script>
<meta name="analytics_debug" value="<%= ENV.fetch('ANALYTICS_DEBUG', 1) %>">

0 comments on commit 14754c1

Please sign in to comment.