Skip to content

Commit b9c62d7

Browse files
authored
Merge pull request #379 from MITLibraries/use-504
USE-504: Adding tab tracking to event names
2 parents 9463976 + 2f6bea2 commit b9c62d7

10 files changed

Lines changed: 32 additions & 30 deletions

app/javascript/matomo_tracking.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//
66
// CLICK TRACKING
77
// Add `data-matomo-click="Category, Action, Name"` to any element to track
8-
// clicks as Matomo events. The Name segment is optional. We have a convention
9-
// of using semicolons inside Name to divide multiple values.
8+
// clicks as Matomo events. We have a convention of using semicolons inside Name
9+
// to divide multiple values. This is purely for consistency.
1010
//
1111
// This tracking can be placed directly on an interactive element.
1212
// Tracking also works if placed on a container. The script will look
@@ -16,22 +16,22 @@
1616
//
1717
// Examples:
1818
// <a href="/file.pdf" data-matomo-click="Downloads, PDF Click, My Paper">Download</a>
19-
// <button data-matomo-click="Search, Boolean Toggle">AND/OR</button>
19+
// <button data-matomo-click="Search, Boolean Toggle, Off">AND/OR</button>
2020
//
2121
// Event delegation on `document` means this works for elements loaded
2222
// asynchronously (Turbo frames, content-loader, etc.) without re-binding.
2323
//
2424
// SEEN TRACKING
2525
// Add `data-matomo-seen="Category, Action, Name"` to any element to fire a
26-
// Matomo event when that element becomes visible in the viewport. The Name
27-
// segment is optional. We have a convention of using semicolons inside Name
28-
// to divide multiple values. Each element fires at most once per page load.
26+
// Matomo event when that element becomes visible in the viewport. We have
27+
// a convention of using semicolons inside Name to divide multiple values.
28+
// Each element fires at most once per page load.
2929
// Works for elements present on initial page load and for elements injected
3030
// later by Turbo frames or async content loaders.
3131
//
3232
// Examples:
3333
// <div data-matomo-seen="Impressions, Result Card, Alma">...</div>
34-
// <a data-matomo-seen="Promotions, Banner Shown">...</a>
34+
// <a data-matomo-seen="Promotions, Banner Shown, Banner Type">...</a>
3535
//
3636
// DYNAMIC VALUES
3737
// Wrap a helper name in double curly braces anywhere inside a segment to have

app/views/layouts/_site_header.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="institute-bar" data-matomo-seen="Navigation, Header Links Seen" data-matomo-click="Navigation, Header Links Engaged, Link: {{getElementText}}">
1+
<div class="institute-bar" data-matomo-seen="Navigation, Header Links Seen, Tab: {{getActiveTabName}}" data-matomo-click="Navigation, Header Links Engaged, Link: {{getElementText}}">
22
<div class="wrapper">
33
<a class="link-logo-mit" href="https://www.mit.edu" ><span class="sr">MIT Logo</span>
44
<img src="https://cdn.libraries.mit.edu/files/branding/local/mit_logo_std_rgb_white.svg" height="24" alt="MIT logo" >
@@ -26,5 +26,5 @@
2626
<% end %>
2727
</header>
2828
<%= render partial: 'search/form' unless Feature.enabled?(:geodata) %>
29-
</div>
29+
</div>
3030
</div>

app/views/layouts/application.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<%= render partial: "layouts/global_alert" %>
1212

1313
<%= render partial: "layouts/site_header" %>
14-
14+
1515
<div class="wrap-outer-content layout-band">
1616
<div class="wrap-content">
1717
<%= render partial: "layouts/flash" %>
@@ -22,7 +22,7 @@
2222
</div>
2323
</div>
2424

25-
<footer data-matomo-seen="Navigation, Footer Links Seen" data-matomo-click="Navigation, Footer Links Engaged, Link: {{getElementText}}">
25+
<footer data-matomo-seen="Navigation, Footer Links Seen, Tab: {{getActiveTabName}}" data-matomo-click="Navigation, Footer Links Engaged, Link: {{getElementText}}">
2626
<%= render partial: "layouts/libraries_footer" %>
2727
<%= render partial: "layouts/institute_footer" %>
2828
</footer>

app/views/search/_form.html.erb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,32 @@
88
<input id="tab-to-target" type="hidden" name="tab" value="<%= @active_tab %>">
99
<button type="submit" class="btn button-primary">Search</button>
1010
</div>
11-
<div class="search-actions" data-matomo-click="Search, Advanced Search Engaged">
11+
<div class="search-actions" data-matomo-click="Search, Advanced Search Engaged, Tab: {{getActiveTabName}}">
1212
<a href="https://libraries.mit.edu/search-advanced">Advanced search</a>
1313
</div>
1414
</form>
1515

1616
<% if Feature.enabled?(:boolean_picker) %>
1717
<aside class="panel panel-info">
1818
<div class="panel-heading">
19-
<% if cookies[:boolean_type].present? %>
20-
<p>Your boolean preference for this session is: <%= cookies[:boolean_type] %></p>
21-
<% else %>
22-
<p>No preference is set. Default boolean preference (`AND`) is enabled.</p>
23-
<% end %>
19+
<p>
20+
<% if cookies[:boolean_type].present? %>
21+
Your boolean preference for this session is: <%= cookies[:boolean_type] %>
22+
<% else %>
23+
No preference is set. Default boolean preference (`AND`) is enabled.
24+
<% end %>
25+
</p>
2426
</div>
2527
<div class="panel-body">
2628
<p>Change to:</p>
2729
<ul>
28-
<% ENV.fetch('BOOLEAN_OPTIONS', 'AND,OR').split(',').each do |opt| %>
29-
<li><%= link_to(opt, boolpref_path(boolean_type: opt)) %></li>
30-
<% end %>
30+
<% ENV.fetch('BOOLEAN_OPTIONS', 'AND,OR').split(',').each do |opt| %>
31+
<li><%= link_to(opt, boolpref_path(boolean_type: opt)) %></li>
32+
<% end %>
3133
<li><%= link_to('Clear preference', boolpref_path()) %></li>
3234
</ul>
3335
</div>
34-
</aside>
36+
</aside>
3537
<% end %>
3638

3739
<%= render partial: 'search/source_tabs' if params[:q].present? %>

app/views/search/_results_callouts.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="callout-wrapper" data-track-content data-content-name="Search Suggestions" data-matomo-seen="Search Suggestions, Search Suggestions Seen" data-matomo-click="Search Suggestions, Search Suggestions Engaged, Link: {{getElementText}}">
1+
<div class="callout-wrapper" data-track-content data-content-name="Search Suggestions" data-matomo-seen="Search Suggestions, Search Suggestions Seen, Tab: {{getActiveTabName}}" data-matomo-click="Search Suggestions, Search Suggestions Engaged, Link: {{getElementText}}">
22
<% if ['cdi', 'alma', 'all'].include?(@active_tab) %>
33
<%= render partial: "results_callout_component", locals: {
44
fa_name: 'magnifying-glass',

app/views/search/_results_sidebar.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<aside id="results-sidebar">
22
<%= render partial: "results_callouts" %>
3-
<div class="core-sidebar-items" data-track-content data-content-name="Sidebar Links" data-matomo-seen="Sidebar Links, Sidebar Links Seen" data-matomo-click="Sidebar Links, Sidebar Links Engaged, Link: {{getElementText}}">
3+
<div class="core-sidebar-items" data-track-content data-content-name="Sidebar Links" data-matomo-seen="Sidebar Links, Sidebar Links Seen, Tab: {{getActiveTabName}}" data-matomo-click="Sidebar Links, Sidebar Links Engaged, Link: {{getElementText}}">
44
<div>
55
<i class="fa-light fa-message"></i>
66
<div>

app/views/search/results.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<%= render(partial: 'trigger_tacos') if tacos_enabled? %>
1111

1212
<%= turbo_frame_tag "search-results", data: { turbo_action: "advance" } do %>
13-
<div id="results-section" data-matomo-seen="Search, Search Performed">
13+
<div id="results-section" data-matomo-seen="Search, Search Performed, Tab: {{getActiveTabName}}">
1414

1515
<% if @show_primo_continuation %>
1616

app/views/tacos/analyze.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% if @suggestions.present? && !Feature.enabled?(:geodata) %>
2-
<div id="hint" aria-live="polite" data-matomo-seen="Interventions, Intervention Shown" data-track-content data-content-name="Intervention">
2+
<div id="hint" aria-live="polite" data-matomo-seen="Interventions, Intervention Shown, Tab: {{getActiveTabName}}" data-track-content data-content-name="Intervention">
33
<aside class="mitlib-suggestion-panel">
44
<div class="panel-content">
55
<h2 class="panel-type">Suggested resource</h2>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<% if ThirdIron.enabled? && @browzine.present? %>
22
<% if @browzine[:browzine_link].present? %>
33
<div class="libkey-actions">
4-
<%= link_to @browzine[:browzine_link][:text], @browzine[:browzine_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, Browzine Link Seen", matomo_click: "Results, Browzine Link Engaged, Link: {{getElementText}}", content_piece: @browzine[:browzine_link][:text] } %>
4+
<%= link_to @browzine[:browzine_link][:text], @browzine[:browzine_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, Browzine Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Browzine Link Engaged, Link: {{getElementText}}", content_piece: @browzine[:browzine_link][:text] } %>
55
</div>
66
<% end %>
77
<% end %>

app/views/thirdiron/libkey.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<% if ThirdIron.enabled? && @libkey.present? %>
22
<% if @libkey[:pdf_link].present? || @libkey[:html_link].present? %>
33
<% if @libkey[:pdf_link].present? %>
4-
<%= link_to( @libkey[:pdf_link][:text], @libkey[:pdf_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, LibKey Link Seen", matomo_click: "Results, LibKey Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:pdf_link][:text] } ) %>
4+
<%= link_to( @libkey[:pdf_link][:text], @libkey[:pdf_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, LibKey Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, LibKey Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:pdf_link][:text] } ) %>
55
<% end %>
66

77
<% if @libkey[:html_link].present? %>
8-
<%= link_to( @libkey[:html_link][:text], @libkey[:html_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, LibKey Link Seen", matomo_click: "Results, LibKey Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:html_link][:text] } ) %>
8+
<%= link_to( @libkey[:html_link][:text], @libkey[:html_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, LibKey Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, LibKey Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:html_link][:text] } ) %>
99
<% end %>
1010

1111
<%# If we don't have direct links, fall back to best_integrator_link. This allows for things like Article Galaxy links %>
1212
<% elsif @libkey[:best_integrator_link].present? %>
13-
<%= link_to( @libkey[:best_integrator_link][:text], @libkey[:best_integrator_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, LibKey Link Seen", matomo_click: "Results, LibKey Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:best_integrator_link][:text] } ) %>
13+
<%= link_to( @libkey[:best_integrator_link][:text], @libkey[:best_integrator_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, LibKey Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, LibKey Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:best_integrator_link][:text] } ) %>
1414
<% end %>
1515

1616
<%# Display browzine link if available. This should always display if we have it regardless of other links. %>
1717
<% if @libkey[:browzine_link].present? %>
1818
<div class="libkey-actions">
19-
<%= link_to @libkey[:browzine_link][:text], @libkey[:browzine_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, Browzine Link Seen", matomo_click: "Results, Browzine Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:browzine_link][:text] } %>
19+
<%= link_to @libkey[:browzine_link][:text], @libkey[:browzine_link][:link], class: 'button libkey-link', data: { matomo_seen: "Results, Browzine Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Browzine Link Engaged, Link: {{getElementText}}", content_piece: @libkey[:browzine_link][:text] } %>
2020
</div>
2121
<% end %>
2222

0 commit comments

Comments
 (0)