Skip to content

A platform for community discussion. Free, open, simple.

REFACTOR: Remove `Discourse.SiteSettings` from click tracking

Robin Wardaa2eea772948
diff --git a/app/assets/javascripts/discourse/app/components/discourse-topic.js b/app/assets/javascripts/discourse/app/components/discourse-topic.js
index 7e222e2e61e..93aa5fac9b9 100644
--- a/app/assets/javascripts/discourse/app/components/discourse-topic.js
+++ b/app/assets/javascripts/discourse/app/components/discourse-topic.js
@@ -108,9 +108,7 @@ export default Component.extend(
$(this.element).on(
"click.discourse-redirect",
".cooked a, a.track-link",
- function(e) {
- return ClickTrack.trackClick(e);
- }
+ e => ClickTrack.trackClick(e, this.siteSettings)
);
this.appEvents.on("discourse:focus-changed", this, "gotFocus");
diff --git a/app/assets/javascripts/discourse/app/components/links-redirect.js b/app/assets/javascripts/discourse/app/components/links-redirect.js
index 0ddd92b21bc..17fce6ac310 100644
--- a/app/assets/javascripts/discourse/app/components/links-redirect.js
+++ b/app/assets/javascripts/discourse/app/components/links-redirect.js
@@ -5,8 +5,8 @@ export default Component.extend({
didInsertElement() {
this._super(...arguments);
- $(this.element).on("click.discourse-redirect", "a", function(e) {
- return ClickTrack.trackClick(e);
+ $(this.element).on("click.discourse-redirect", "a", e => {
+ return ClickTrack.trackClick(e, this.siteSettings);
});
},
diff --git a/app/assets/javascripts/discourse/app/components/user-stream.js b/app/assets/javascripts/discourse/app/components/user-stream.js
index aadd188699a..b102eaab73d 100644
--- a/app/assets/javascripts/discourse/app/components/user-stream.js
+++ b/app/assets/javascripts/discourse/app/components/user-stream.js
@@ -40,8 +40,8 @@ export default Component.extend(LoadMore, {
"details.disabled",
() => false
);
- $(this.element).on("click.discourse-redirect", ".excerpt a", function(e) {
- return ClickTrack.trackClick(e);
+ $(this.element).on("click.discourse-redirect", ".excerpt a", e => {
+ return ClickTrack.trackClick(e, this.siteSettings);
});
}),
diff --git a/app/assets/javascripts/discourse/app/lib/click-track.js b/app/assets/javascripts/discourse/app/lib/click-track.js
index d3a37441f77..c408da105b1 100644
--- a/app/assets/javascripts/discourse/app/lib/click-track.js
+++ b/app/assets/javascripts/discourse/app/lib/click-track.js
@@ -35,7 +35,7 @@ export function isValidLink($link) {
}
export default {
- trackClick(e) {
+ trackClick(e, siteSettings) {
// right clicks are not tracked
if (e.which === 3) {
return true;
@@ -65,7 +65,8 @@ export default {
if ($link.hasClass("attachment")) {
// Warn the user if they cannot download the file.
if (
- Discourse.SiteSettings.prevent_anons_from_downloading_files &&
+ siteSettings &&
+ siteSettings.prevent_anons_from_downloading_files &&
!User.current()
) {
bootbox.alert(I18n.t("post.errors.attachment_download_requires_login"));