Skip to content

Commit abfd15d

Browse files
committed
Track download clicks with Plausible
1 parent 266858e commit abfd15d

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

_includes/script.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
{% endif %}
1212

1313
<script defer data-domain="studentrobotics.org" src="https://plausible.io/js/plausible.js"></script>
14+
<script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>
1415

1516
<script src="{{ '/js/navigation.js' | prepend: site.baseurl }}"></script>

_layouts/updates.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,30 @@ <h1>Documentation</h1>
1717
<div class="column m-9-12 doc">
1818
{{ content }}
1919

20-
<table>
20+
<table id="updates-table">
2121
<tr>
2222
<th></th>
2323
<th>Release Date</th>
2424
<th>Download</th>
2525
<th>Licences</th>
2626
</tr>
2727
{% for kit_version in site.data.kit_versions %}
28-
<tr id="{{ kit_version.version | slugify }}">
28+
{% assign version = kit_version.version %}
29+
<tr id="{{ version | slugify }}">
2930
<td>
3031
{% if forloop.first %}
31-
<code><strong>{{ kit_version.version }}</strong></code>
32+
<code><strong>{{ version }}</strong></code>
3233
{% else %}
33-
<code>{{ kit_version.version }}</code>
34+
<code>{{ version }}</code>
3435
{% endif %}
3536
</td>
3637
<td>{{ kit_version.released | date_to_string }}</td>
37-
<td><a href="https://kit-downloads.studentrobotics.org/kit-software/{{ kit_version.version }}/srobo-robot-{{ kit_version.version }}.img.xz">Download <code>{{ kit_version.version }}</code></a></td>
38-
<td><a href="https://kit-downloads.studentrobotics.org/kit-software/{{ kit_version.version }}/srobo-robot-{{ kit_version.version }}-licences">Licences</a></td>
38+
<td>
39+
<a class="kit-download-link" data-version="{{ version }}" href="https://kit-downloads.studentrobotics.org/kit-software/{{ version }}/srobo-robot-{{ version }}.img.xz">
40+
Download {{ version }}
41+
</a>
42+
</td>
43+
<td><a href="https://kit-downloads.studentrobotics.org/kit-software/{{ version }}/srobo-robot-{{ version }}-licences">Licences</a></td>
3944
</tr>
4045
{% endfor %}
4146
</table>

js/updates.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function handleDownloadClick(event) {
2+
plausible("Kit download", {props: {version: event.target.dataset.version}});
3+
4+
// Delay navigation so that Plausible is notified of the click
5+
setTimeout(function() {
6+
location.href = event.target.href;
7+
}, 150);
8+
event.preventDefault();
9+
}
10+
11+
function addDownloadTracking() {
12+
document.querySelectorAll("#updates-table .kit-download-link").forEach(function(link) {
13+
link.addEventListener("click", handleDownloadClick);
14+
});
15+
}
16+
17+
window.addEventListener('load', addDownloadTracking);

updates/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: updates
33
title: Updates
4+
extra_js: updates
45
---
56

67
# Updates

0 commit comments

Comments
 (0)