From 9bba68ed74d0edbaa80353c6358c6080cb9db7c7 Mon Sep 17 00:00:00 2001 From: Peter Lejeck Date: Mon, 11 Apr 2016 08:39:49 -0700 Subject: [PATCH] Allow disabling link tracking with .no-track-link (#4160) --- app/assets/javascripts/discourse/lib/click-track.js.es6 | 2 +- test/javascripts/lib/click-track-test.js.es6 | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/lib/click-track.js.es6 b/app/assets/javascripts/discourse/lib/click-track.js.es6 index 627318a83ee..799c26ada8b 100644 --- a/app/assets/javascripts/discourse/lib/click-track.js.es6 +++ b/app/assets/javascripts/discourse/lib/click-track.js.es6 @@ -11,7 +11,7 @@ export default { if (Discourse.Utilities.selectedText() !== "") { return false; } var $link = $(e.currentTarget); - if ($link.hasClass('lightbox') || $link.hasClass('mention-group')) { return true; } + if ($link.hasClass('lightbox') || $link.hasClass('mention-group') || $link.hasClass('no-track-link')) { return true; } var href = $link.attr('href') || $link.data('href'), $article = $link.closest('article'), diff --git a/test/javascripts/lib/click-track-test.js.es6 b/test/javascripts/lib/click-track-test.js.es6 index 403a2c15f53..ae571b742a0 100644 --- a/test/javascripts/lib/click-track-test.js.es6 +++ b/test/javascripts/lib/click-track-test.js.es6 @@ -27,6 +27,7 @@ module("lib:click-track", { google.com1 google.com1 + google.com forum log.txt #hashtag @@ -57,6 +58,10 @@ test("it calls preventDefault when clicking on an a", function() { ok(DiscourseURL.redirectTo.calledOnce); }); +test("does not track clicks when forcibly disabled", function() { + ok(track(generateClickEventOn('.no-track-link'))); +}); + test("does not track clicks on back buttons", function() { ok(track(generateClickEventOn('.back'))); });