Twitter shared URL has a query string

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

1 Like

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?

2 Likes

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:

2 Likes

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.

2 Likes

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>
6 Likes

Appreciate it a lot @vinothkannans

1 Like

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.