Skip to content

Commit

Permalink
FIX: don't track clicks on links in quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed May 3, 2016
1 parent c069488 commit ad15049
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
13 changes: 11 additions & 2 deletions app/assets/javascripts/discourse/lib/click-track.js.es6
Expand Up @@ -12,15 +12,24 @@ 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'),
postId = $article.data('post-id'),
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');

Expand Down
2 changes: 1 addition & 1 deletion test/javascripts/lib/click-track-edit-history-test.js.es6
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/javascripts/lib/click-track-profile-page-test.js.es6
Expand Up @@ -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() {
Expand Down
14 changes: 13 additions & 1 deletion test/javascripts/lib/click-track-test.js.es6
Expand Up @@ -31,6 +31,10 @@ module("lib:click-track", {
<a id="same-site" href="http://discuss.domain.com">forum</a>
<a class="attachment" href="http://discuss.domain.com/uploads/default/1234/1532357280.txt">log.txt</a>
<a class="hashtag" href="http://discuss.domain.com">#hashtag</a>
<a class="mailto" href="mailto:foo@bar.com">email-me</a>
<aside class="quote">
<a class="inside-quote" href="http://discuss.domain.com">foobar</a>
</aside>
</article>
</div>`);
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ad15049

Please sign in to comment.