From 50495ae2414906ad555c87d767837cfb1766508b Mon Sep 17 00:00:00 2001 From: lassenordahl Date: Tue, 20 Feb 2024 17:34:33 -0500 Subject: [PATCH] customscripts/releases: add `binary-link` class for tracking binary downloads This PR adds an event listener on all items in the view that have links to binary downloads. Clicking on a link triggers a segment event that recorsd the URL and `href` that the user requested a binary for. Release note: None --- src/current/js/customscripts.js | 28 +++++++++++++++++++++------ src/current/releases/index.md | 34 ++++++++++++++++----------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/current/js/customscripts.js b/src/current/js/customscripts.js index 9f597e97001..525b6392b55 100755 --- a/src/current/js/customscripts.js +++ b/src/current/js/customscripts.js @@ -441,11 +441,15 @@ $(function() { clipboard.on('success', function(e) { $(e.trigger).addClass('copy-clipboard--copied'); - $(e.trigger).find('.copy-clipboard__text').text('copied'); + // $(e.trigger).find('.copy-clipboard__text').text('copied'); + // On successful copy, send an event to Segment. This event will be used to + // track the text that was copied and the URL of the page where the copy. try { + // Wrap the event submission in a try-catch block to handle cases of + // `window.analytics` not yet being defined yet (on load of the page). window.analytics.track("copied_core_download_link", { - text: e.text, // The copied text is sent as a property. + text: e.text, url: window.location.href, }); } catch (e) { @@ -489,9 +493,21 @@ $(function() { return this.hostname && this.hostname !== location.hostname && cockroachDomains.includes(this.hostname); }).addClass('external').attr("target","_blank").attr("rel","noopener"); -}); + // Attach a binary-link click event listener to all binary links on the page. + // This event listener will send an event to Segment when a binary link is clicked. + document.querySelectorAll("a.binary-link").forEach(link => { + link.addEventListener("click", function() { + const href = this.getAttribute('href'); -// $('.nav-docs-mobile').on('click', function(){ -// $('#sidebarMenu').collapse(); -// }); + try { + window.analytics.track("binary_link_clicked", { + binaryUrl: href, + currentPage: window.location.href, + }); + } catch (error) { + console.error("Error submitting event", error); + } + }); + }); +}); diff --git a/src/current/releases/index.md b/src/current/releases/index.md index a9417774619..1a9aa8eb0fd 100644 --- a/src/current/releases/index.md +++ b/src/current/releases/index.md @@ -111,7 +111,7 @@ As of 2024, CockroachDB is released under a staged delivery process. New release {% for r in releases %} {% comment %} Add "Latest" class to release if it's the latest release. {% endcomment %} - {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} + {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} {% if r.release_name == latest_hotfix.release_name %} Latest {% comment %} Add "Latest" badge to release if it's the latest release. {% endcomment %} {% endif %} @@ -124,9 +124,9 @@ As of 2024, CockroachDB is released under a staged delivery process. New release {% continue %} {% else %} {% comment %} Add download links for all non-withdrawn versions. {% endcomment %} -
Full Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
Full Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% if r.has_sql_only == true %} -
SQL Shell Binary{% if r.has_sha256sum == true %} (SHA256{% endif %})
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
SQL Shell Binary{% if r.has_sha256sum == true %} (SHA256{% endif %})
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% endif %} {% endif %} {% if r.linux.linux_arm == true %} @@ -136,9 +136,9 @@ As of 2024, CockroachDB is released under a staged delivery process. New release {% else %} {% if r.linux.linux_arm_experimental == true %}Experimental:{% endif %} -
Full Binary{% if r.has_sha256sum == true %} (SHA256{% endif %})
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
Full Binary{% if r.has_sha256sum == true %} (SHA256{% endif %})
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% if r.has_sql_only == true %} -
SQL shell Binary{% if r.has_sha256sum == true %} (SHA256{% endif %})
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
SQL shell Binary{% if r.has_sha256sum == true %} (SHA256{% endif %})
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% endif %} {% endif %} @@ -168,7 +168,7 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% for r in releases %} {% comment %} Add "Latest" class to release if it's the latest release. {% endcomment %} - {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} + {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} {% if r.release_name == latest_hotfix.release_name %} Latest {% comment %} Add "Latest" badge to release if it's the latest release. {% endcomment %} {% endif %} @@ -181,9 +181,9 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% continue %} {% else %} {% comment %} Add download links for all non-withdrawn versions. {% endcomment %} -
Full Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
Full Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% if r.has_sql_only == true %} -
SQL shell Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
SQL shell Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% endif %} {% endif %} {% if r.mac.mac_arm == true %} @@ -192,9 +192,9 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% break %} {% else %} -
Full Binary(SHA256)
+
Full Binary(SHA256)
{% if r.has_sql_only == true %} -
SQL shell Binary(SHA256)
+
SQL shell Binary(SHA256)
{% endif %} {% endif %} @@ -221,7 +221,7 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% for r in releases %} {% comment %} Add "Latest" class to release if it's the latest release. {% endcomment %} - {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} + {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} {% if r.release_name == latest_hotfix.release_name %} Latest {% comment %} Add "Latest" badge to release if it's the latest release. {% endcomment %} {% endif %} @@ -235,9 +235,9 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% else %} {% comment %} Add download links for all non-withdrawn versions. {% endcomment %} {% if r.windows == true %} -
Full Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
Full Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% if r.has_sql_only == true %} -
SQL shell Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} +
SQL shell Binary{% if r.has_sha256sum == true %} (SHA256){% endif %}
{% comment %} If a sha256sum is available for a particular release, we display a link to the file containing the sha256sum alongside the download link of the release. {% endcomment %} {% endif %} {% else %} N/A @@ -271,7 +271,7 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% for r in releases %} {% comment %} Add "Latest" class to release if it's the latest release. {% endcomment %} - {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} + {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} {% if r.release_name == latest_hotfix.release_name %} Latest {% comment %} Add "Latest" badge to release if it's the latest release. {% endcomment %} {% endif %} @@ -307,7 +307,7 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi
-

The source code for CockroachDB is hosted in the cockroachdb/cockroach repository on Github.

+

The source code for CockroachDB is hosted in the cockroachdb/cockroach repository on Github.

@@ -320,7 +320,7 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% for r in releases %} {% comment %} Add "Latest" class to release if it's the latest release. {% endcomment %}
- {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} + {{ r.release_name }} {% comment %} Add link to each release r. {% endcomment %} {% if r.release_name == latest_hotfix.release_name %} Latest {% comment %} Add "Latest" badge to release if it's the latest release. {% endcomment %} {% endif %} @@ -334,7 +334,7 @@ macOS downloads are **experimental**. Experimental downloads are not yet qualifi {% else %} {% comment %} Add download links for all non-withdrawn versions. {% endcomment %} {% if r.source == true %} - View on Github + View on Github {% else %} N/A {% endif %}