When I share a post via twitter it ads a query string e.g. ?u=[theusername] to the URL that is being shared. Is there a way to remove it?
It is useful option to know about who shared the link. Why would you like to remove that?
Anyway you can check previous discussion here
I prefer the links to be plain for crawlers, because canonical links are not always obeyed by Google crawler. It can be done using hash and send to the server via webservice, instead of doing t on the server by reading the query string. And regarding the link to the post, you better off using the userId, not the username.
If you hash the name in some way, youâre still not getting a âcleanâ URL for Google to index. Also, do you have any authoritative source for the suggestion that the googlebot doesnât always respect canonical URLs? That would be something of a bug in Googleâs crawler, and something that could be reported to Google and fixed.
I donât understand what you mean by this. If you mean that the fact that the link was clicked could be sent to the server via JavaScript, then no, it canât, because itâs pretty rare for people to be able to include active content in the links they post elsewhere.
Why?
It is part of Googleâs documentation on using canonical URLs.
Is this documentation available on the Internet?
Why I want to track which user shared posts on twitter. I think URLs should always be clean, both to crawlers and users.
Here:
I think Iâll just tell Google to ignore the query string in the webmaster tools
I think, in this case, Google will recognize that the canonical is just having the querystring removed, and is more likely to respect that than changing from the .../topicid/post
to .../topicid?page=3
format.
I do believe that as well, and I donât see it as a big issue, but as I said, I would prefer not having it. We actually have other things that we should work on, and this one has little or no priority.
Okay. If you still prefer to not having it add the below javascript in your discourse customization. Itâs working fine for me as you wanted.
<script>
jQuery( document ).ready(function() {
$('#main').on('click', '.widget-button.share', function () {
var url = $(this).attr('data-share-url');
var i = url.indexOf('?');
if(i > 0)
url = url.substring(0, i);
$(this).attr('data-share-url', url);
});
});
</script>
Appreciate it a lot @vinothkannans
Thanks @Idan. But still having username as query when user navigated from another url to topic. So I just updated the code in above answer to fix.
Tell me, in the admin you can see who shared the posts, thatâs the idea behind the query string?
Yes. In âTop Referrersâ section at admin dashboard you can check who gave most traffic to your site by referral links
You can also track these details in Google Analytics and other platforms.
And you lose the share related badgesâŚ
This topic was automatically closed after 2882 days. New replies are no longer allowed.