FIX: Don't track category-badges links.
This commit is contained in:
parent
7303f8f309
commit
9652c3df4f
|
@ -1,5 +1,11 @@
|
||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
|
|
||||||
|
export function isValidLink($link) {
|
||||||
|
return ($link.hasClass("track-link") ||
|
||||||
|
($link.closest('.onebox-result,.onebox-body').length === 0 &&
|
||||||
|
$link.has('.badge-category').length === 0))
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
trackClick(e) {
|
trackClick(e) {
|
||||||
// cancel click if triggered as part of selection.
|
// cancel click if triggered as part of selection.
|
||||||
|
@ -32,8 +38,7 @@ export default {
|
||||||
var $badge = $('span.badge', $link);
|
var $badge = $('span.badge', $link);
|
||||||
if ($badge.length === 1) {
|
if ($badge.length === 1) {
|
||||||
// don't update counts in category badge nor in oneboxes (except when we force it)
|
// don't update counts in category badge nor in oneboxes (except when we force it)
|
||||||
if ($link.hasClass("track-link") ||
|
if (isValidLink($link)) {
|
||||||
$link.closest('.badge-category,.onebox-result,.onebox-body').length === 0) {
|
|
||||||
var html = $badge.html();
|
var html = $badge.html();
|
||||||
if (/^\d+$/.test(html)) { $badge.html(parseInt(html, 10) + 1); }
|
if (/^\d+$/.test(html)) { $badge.html(parseInt(html, 10) + 1); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import DiscourseURL from 'discourse/lib/url';
|
||||||
import { default as computed, on } from 'ember-addons/ember-computed-decorators';
|
import { default as computed, on } from 'ember-addons/ember-computed-decorators';
|
||||||
import { fmt } from 'discourse/lib/computed';
|
import { fmt } from 'discourse/lib/computed';
|
||||||
import { decorateLinks as decorateCategoryHashtagLinks } from 'discourse/lib/category-hashtags';
|
import { decorateLinks as decorateCategoryHashtagLinks } from 'discourse/lib/category-hashtags';
|
||||||
|
import { isValidLink } from 'discourse/lib/click-track';
|
||||||
|
|
||||||
const DAY = 60 * 50 * 1000;
|
const DAY = 60 * 50 * 1000;
|
||||||
|
|
||||||
|
@ -194,8 +195,7 @@ const PostView = Discourse.GroupedView.extend(Ember.Evented, {
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
// don't display badge counts on category badge & oneboxes (unless when explicitely stated)
|
// don't display badge counts on category badge & oneboxes (unless when explicitely stated)
|
||||||
if ($link.hasClass("track-link") ||
|
if (isValidLink($link)) {
|
||||||
$link.closest('.badge-category,.onebox-result,.onebox-body').length === 0) {
|
|
||||||
$link.append("<span class='badge badge-notification clicks' title='" + I18n.t("topic_map.clicks", {count: lc.clicks}) + "'>" + number(lc.clicks) + "</span>");
|
$link.append("<span class='badge badge-notification clicks' title='" + I18n.t("topic_map.clicks", {count: lc.clicks}) + "'>" + number(lc.clicks) + "</span>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,21 +16,25 @@ module("lib:click-track", {
|
||||||
windowOpen = sandbox.stub(window, "open").returns(win);
|
windowOpen = sandbox.stub(window, "open").returns(win);
|
||||||
sandbox.stub(win, "focus");
|
sandbox.stub(win, "focus");
|
||||||
|
|
||||||
fixture().html([
|
fixture().html(
|
||||||
'<div id="topic" id="1337">',
|
`<div id="topic" id="1337">
|
||||||
' <article data-post-id="42" data-user-id="3141">',
|
<article data-post-id="42" data-user-id="3141">
|
||||||
' <a href="http://www.google.com">google.com</a>',
|
<a href="http://www.google.com">google.com</a>
|
||||||
' <a class="lightbox back quote-other-topic" href="http://www.google.com">google.com</a>',
|
<a class="lightbox back quote-other-topic" href="http://www.google.com">google.com</a>
|
||||||
' <a id="with-badge" data-user-id="314" href="http://www.google.com">google.com<span class="badge">1</span></a>',
|
<a id="with-badge" data-user-id="314" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
||||||
' <a id="with-badge-but-not-mine" href="http://www.google.com">google.com<span class="badge">1</span></a>',
|
<a id="with-badge-but-not-mine" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
||||||
' <div class="onebox-result">',
|
<div class="onebox-result">
|
||||||
' <a id="inside-onebox" href="http://www.google.com">google.com<span class="badge">1</span></a>',
|
<a id="inside-onebox" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
||||||
' <a id="inside-onebox-forced" class="track-link" href="http://www.google.com">google.com<span class="badge">1</span></a>',
|
<a id="inside-onebox-forced" class="track-link" href="http://www.google.com">google.com<span class="badge">1</span></a>
|
||||||
' </div>',
|
</div>
|
||||||
' <a id="same-site" href="http://discuss.domain.com">forum</a>',
|
<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="attachment" href="http://discuss.domain.com/uploads/default/1234/1532357280.txt">log.txt</a>
|
||||||
' </article>',
|
<a class="badge-wrapper bullet" href="http://discuss.domain.com">
|
||||||
'</div>'].join("\n"));
|
<span class="badge-category-bg"></span>
|
||||||
|
<span class="badge-category"></span>
|
||||||
|
</a>
|
||||||
|
</article>
|
||||||
|
</div>`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,6 +68,10 @@ test("does not track clicks on quote buttons", function() {
|
||||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("does not track clicks on category badges", () => {
|
||||||
|
ok(!track(generateClickEventOn('.badge-wrapper')));
|
||||||
|
});
|
||||||
|
|
||||||
test("removes the href and put it as a data attribute", function() {
|
test("removes the href and put it as a data attribute", function() {
|
||||||
track(generateClickEventOn('a'));
|
track(generateClickEventOn('a'));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue