diff --git a/app/assets/javascripts/discourse/lib/click-track.js.es6 b/app/assets/javascripts/discourse/lib/click-track.js.es6 index b36e97cdf89..775a638c7fe 100644 --- a/app/assets/javascripts/discourse/lib/click-track.js.es6 +++ b/app/assets/javascripts/discourse/lib/click-track.js.es6 @@ -12,7 +12,15 @@ export default { if (Discourse.Utilities.selectedText() !== "") { return false; } var $link = $(e.currentTarget); - if ($link.hasClass('lightbox') || $link.hasClass('mention-group') || $link.hasClass('no-track-link')) { return true; } + + // don't track lightboxes, group mentions or links with disabled tracking + if ($link.hasClass('lightbox') || $link.hasClass('mention-group') || + $link.hasClass('no-track-link') || $link.hasClass('hashtag')) { + return true; + } + + // don't track links in quotes or in elided part + if ($link.parents('aside.quote,.elided').length) { return true; } var href = $link.attr('href') || $link.data('href'), $article = $link.closest('article,.excerpt,#revisions'), @@ -20,7 +28,8 @@ export default { topicId = $('#topic').data('topic-id') || $article.data('topic-id'), userId = $link.data('user-id'); - if (!href || href.trim().length === 0 || href.indexOf("mailto:") === 0) { return; } + if (!href || href.trim().length === 0) { return false; } + if (href.indexOf("mailto:") === 0) { return true; } if (!userId) userId = $article.data('user-id'); diff --git a/test/javascripts/lib/click-track-edit-history-test.js.es6 b/test/javascripts/lib/click-track-edit-history-test.js.es6 index d7fa2623431..f0973679be3 100644 --- a/test/javascripts/lib/click-track-edit-history-test.js.es6 +++ b/test/javascripts/lib/click-track-edit-history-test.js.es6 @@ -85,7 +85,7 @@ test("does not track clicks on quote buttons", function() { }); test("does not track clicks on category badges", () => { - ok(!track(generateClickEventOn('.hashtag'))); + ok(track(generateClickEventOn('.hashtag'))); }); test("removes the href and put it as a data attribute", function() { diff --git a/test/javascripts/lib/click-track-profile-page-test.js.es6 b/test/javascripts/lib/click-track-profile-page-test.js.es6 index d224421b2b5..cf6233fc3f9 100644 --- a/test/javascripts/lib/click-track-profile-page-test.js.es6 +++ b/test/javascripts/lib/click-track-profile-page-test.js.es6 @@ -79,7 +79,7 @@ test("does not track clicks on quote buttons", function() { }); test("does not track clicks on category badges", () => { - ok(!track(generateClickEventOn('.hashtag'))); + ok(track(generateClickEventOn('.hashtag'))); }); test("removes the href and put it as a data attribute", function() { diff --git a/test/javascripts/lib/click-track-test.js.es6 b/test/javascripts/lib/click-track-test.js.es6 index 305ae0664ba..806b6b55753 100644 --- a/test/javascripts/lib/click-track-test.js.es6 +++ b/test/javascripts/lib/click-track-test.js.es6 @@ -31,6 +31,10 @@ module("lib:click-track", { forum log.txt #hashtag + email-me + `); } @@ -66,12 +70,20 @@ test("does not track clicks on back buttons", function() { ok(track(generateClickEventOn('.back'))); }); +test("does not track clicks in quotes", function() { + ok(track(generateClickEventOn('.inside-quote'))); +}); + test("does not track clicks on quote buttons", function() { ok(track(generateClickEventOn('.quote-other-topic'))); }); test("does not track clicks on category badges", () => { - ok(!track(generateClickEventOn('.hashtag'))); + ok(track(generateClickEventOn('.hashtag'))); +}); + +test("does not track clicks on mailto", function() { + ok(track(generateClickEventOn('.mailto'))); }); test("removes the href and put it as a data attribute", function() {