don't track links in oneboxes
This commit is contained in:
parent
3ba0bf6d5d
commit
d080ae4d2d
|
@ -14,38 +14,39 @@ Discourse.ClickTrack = {
|
||||||
@param {jQuery.Event} e The click event that occurred
|
@param {jQuery.Event} e The click event that occurred
|
||||||
**/
|
**/
|
||||||
trackClick: function(e) {
|
trackClick: function(e) {
|
||||||
var $a, $article, $badge, count, destination, href, ownLink, postId, topicId, trackingUrl, userId;
|
var $link = $(e.currentTarget);
|
||||||
$a = $(e.currentTarget);
|
if ($link.hasClass('lightbox')) return true;
|
||||||
if ($a.hasClass('lightbox')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// We don't track clicks on quote back buttons
|
// We don't track clicks on quote back buttons
|
||||||
if ($a.hasClass('back') || $a.hasClass('quote-other-topic')) return true;
|
if ($link.hasClass('back') || $link.hasClass('quote-other-topic')) return true;
|
||||||
|
|
||||||
|
// We don't track clicks in oneboxes
|
||||||
|
// except when we force it with the "track-link" class
|
||||||
|
if ($link.closest('.onebox-result') && !$link.hasClass('track-link')) return true;
|
||||||
|
|
||||||
// Remove the href, put it as a data attribute
|
// Remove the href, put it as a data attribute
|
||||||
if (!$a.data('href')) {
|
if (!$link.data('href')) {
|
||||||
$a.addClass('no-href');
|
$link.addClass('no-href');
|
||||||
$a.data('href', $a.attr('href'));
|
$link.data('href', $link.attr('href'));
|
||||||
$a.attr('href', null);
|
$link.attr('href', null);
|
||||||
// Don't route to this URL
|
// Don't route to this URL
|
||||||
$a.data('auto-route', true);
|
$link.data('auto-route', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
href = $a.data('href');
|
var href = $link.data('href'),
|
||||||
$article = $a.closest('article');
|
$article = $link.closest('article'),
|
||||||
postId = $article.data('post-id');
|
postId = $article.data('post-id'),
|
||||||
topicId = $('#topic').data('topic-id');
|
topicId = $('#topic').data('topic-id'),
|
||||||
userId = $a.data('user-id');
|
userId = $link.data('user-id');
|
||||||
if (!userId) {
|
|
||||||
userId = $article.data('user-id');
|
if (!userId) userId = $article.data('user-id');
|
||||||
}
|
var ownLink = userId && (userId === Discourse.get('currentUser.id'));
|
||||||
ownLink = userId && (userId === Discourse.get('currentUser.id'));
|
|
||||||
|
|
||||||
// Build a Redirect URL
|
// Build a Redirect URL
|
||||||
trackingUrl = Discourse.getURL("/clicks/track?url=" + encodeURIComponent(href));
|
var trackingUrl = Discourse.getURL("/clicks/track?url=" + encodeURIComponent(href));
|
||||||
if (postId && (!$a.data('ignore-post-id'))) {
|
if (postId && (!$link.data('ignore-post-id'))) {
|
||||||
trackingUrl += "&post_id=" + encodeURI(postId);
|
trackingUrl += "&post_id=" + encodeURI(postId);
|
||||||
}
|
}
|
||||||
if (topicId) {
|
if (topicId) {
|
||||||
|
@ -54,23 +55,21 @@ Discourse.ClickTrack = {
|
||||||
|
|
||||||
// Update badge clicks unless it's our own
|
// Update badge clicks unless it's our own
|
||||||
if (!ownLink) {
|
if (!ownLink) {
|
||||||
$badge = $('span.badge', $a);
|
var $badge = $('span.badge', $link);
|
||||||
if ($badge.length === 1) {
|
if ($badge.length === 1) {
|
||||||
count = parseInt($badge.html(), 10);
|
$badge.html(parseInt($badge.html(), 10) + 1);
|
||||||
$badge.html(count + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If they right clicked, change the destination href
|
// If they right clicked, change the destination href
|
||||||
if (e.which === 3) {
|
if (e.which === 3) {
|
||||||
destination = Discourse.SiteSettings.track_external_right_clicks ? trackingUrl : href;
|
var destination = Discourse.SiteSettings.track_external_right_clicks ? trackingUrl : href;
|
||||||
$a.attr('href', destination);
|
$link.attr('href', destination);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if they want to open in a new tab, do an AJAX request
|
// if they want to open in a new tab, do an AJAX request
|
||||||
if (e.metaKey || e.ctrlKey || e.which === 2) {
|
if (e.metaKey || e.ctrlKey || e.which === 2) {
|
||||||
|
|
||||||
Discourse.ajax(Discourse.getURL("/clicks/track"), {
|
Discourse.ajax(Discourse.getURL("/clicks/track"), {
|
||||||
data: {
|
data: {
|
||||||
url: href,
|
url: href,
|
||||||
|
@ -101,8 +100,7 @@ Discourse.ClickTrack = {
|
||||||
if (Discourse.get('currentUser.external_links_in_new_tab')) {
|
if (Discourse.get('currentUser.external_links_in_new_tab')) {
|
||||||
var win = window.open(trackingUrl, '_blank');
|
var win = window.open(trackingUrl, '_blank');
|
||||||
win.focus();
|
win.focus();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
window.location = trackingUrl;
|
window.location = trackingUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class='onebox-result'>
|
<div class='onebox-result'>
|
||||||
{{#host}}
|
{{#host}}
|
||||||
<a href='{{original_url}}' class='source' target="_blank">
|
<a href='{{original_url}}' class='source track-link' target="_blank">
|
||||||
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
||||||
</a>
|
</a>
|
||||||
{{/host}}
|
{{/host}}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class='onebox-result'>
|
<div class='onebox-result'>
|
||||||
{{#host}}
|
{{#host}}
|
||||||
<a href='{{original_url}}' class='source' target="_blank">
|
<a href='{{original_url}}' class='source track-link' target="_blank">
|
||||||
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
||||||
</a>
|
</a>
|
||||||
{{/host}}
|
{{/host}}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{{#host}}
|
{{#host}}
|
||||||
<div class="source">
|
<div class="source">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<a href="{{html_url}}" target="_blank">
|
<a href="{{html_url}}" class="track-link" target="_blank">
|
||||||
{{#favicon}}<img class="favicon" src="{{favicon}}"> {{/favicon}}{{host}}
|
{{#favicon}}<img class="favicon" src="{{favicon}}"> {{/favicon}}{{host}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{{#host}}
|
{{#host}}
|
||||||
<div class="source">
|
<div class="source">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<a href='{{original_url}}' class='source' target="_blank">
|
<a href='{{original_url}}' class='source track-link' target="_blank">
|
||||||
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{{#host}}
|
{{#host}}
|
||||||
<div class='source'>
|
<div class='source'>
|
||||||
<div class='info'>
|
<div class='info'>
|
||||||
<a href='{{original_url}}' target="_blank">
|
<a href='{{original_url}}' class="track-link" target="_blank">
|
||||||
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{{#host}}
|
{{#host}}
|
||||||
<div class="source">
|
<div class="source">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<a href='{{original_url}}' target="_blank">
|
<a href='{{original_url}}' class="track-link" target="_blank">
|
||||||
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
{{#favicon}}<img class='favicon' src="{{favicon}}"> {{/favicon}}{{host}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -24,7 +24,7 @@ private
|
||||||
<div class='onebox-result'>
|
<div class='onebox-result'>
|
||||||
<div class='source'>
|
<div class='source'>
|
||||||
<div class='info'>
|
<div class='info'>
|
||||||
<a href='http://www.amazon.com/Ruby-Programming-Language-David-Flanagan/dp/0596516177' target="_blank">
|
<a href='http://www.amazon.com/Ruby-Programming-Language-David-Flanagan/dp/0596516177' class="track-link" target="_blank">
|
||||||
<img class='favicon' src="/assets/favicons/amazon.png"> amazon.com
|
<img class='favicon' src="/assets/favicons/amazon.png"> amazon.com
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,7 +20,7 @@ private
|
||||||
<div class='onebox-result'>
|
<div class='onebox-result'>
|
||||||
<div class='source'>
|
<div class='source'>
|
||||||
<div class='info'>
|
<div class='info'>
|
||||||
<a href='https://play.google.com/store/apps/details?id=com.moosoft.parrot' target="_blank">
|
<a href='https://play.google.com/store/apps/details?id=com.moosoft.parrot' class="track-link" target="_blank">
|
||||||
<img class='favicon' src="/assets/favicons/google_play.png"> play.google.com
|
<img class='favicon' src="/assets/favicons/google_play.png"> play.google.com
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,7 +20,7 @@ private
|
||||||
<div class='onebox-result'>
|
<div class='onebox-result'>
|
||||||
<div class='source'>
|
<div class='source'>
|
||||||
<div class='info'>
|
<div class='info'>
|
||||||
<a href='https://itunes.apple.com/us/app/minecraft-pocket-edition-lite/id479651754' target="_blank">
|
<a href='https://itunes.apple.com/us/app/minecraft-pocket-edition-lite/id479651754' class="track-link" target="_blank">
|
||||||
<img class='favicon' src="/assets/favicons/apple.png"> itunes.apple.com
|
<img class='favicon' src="/assets/favicons/apple.png"> itunes.apple.com
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -24,7 +24,7 @@ private
|
||||||
<div class="onebox-result">
|
<div class="onebox-result">
|
||||||
<div class="source">
|
<div class="source">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<a href="https://github.com/discourse/discourse/commit/ee76f1926defa8309b3a7ea64a25707519529a13" target="_blank">
|
<a href="https://github.com/discourse/discourse/commit/ee76f1926defa8309b3a7ea64a25707519529a13" class="track-link" target="_blank">
|
||||||
<img class="favicon" src="/assets/favicons/github.png"> github.com
|
<img class="favicon" src="/assets/favicons/github.png"> github.com
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
|
@ -39,7 +39,7 @@ private
|
||||||
<div class='onebox-result'>
|
<div class='onebox-result'>
|
||||||
<div class='source'>
|
<div class='source'>
|
||||||
<div class='info'>
|
<div class='info'>
|
||||||
<a href='http://en.wikipedia.org/wiki/Ruby' target="_blank">
|
<a href='http://en.wikipedia.org/wiki/Ruby' class="track-link" target="_blank">
|
||||||
<img class='favicon' src="/assets/favicons/wikipedia.png"> en.wikipedia.org
|
<img class='favicon' src="/assets/favicons/wikipedia.png"> en.wikipedia.org
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue