Twitter shared URL has a query string


(Spooky) #1

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?


(Vinoth Kannan) #2

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


(Spooky) #3

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.


(Matt Palmer) #4

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?


(John Muhl) #5

It is part of Google’s documentation on using canonical URLs.


(Matt Palmer) #6

Is this documentation available on the Internet?


(Spooky) #7

Why I want to track which user shared posts on twitter. I think URLs should always be clean, both to crawlers and users.


(Dean Taylor) #8

Here:
https://support.google.com/webmasters/answer/139066?hl=en


(Spooky) #9

I think I’ll just tell Google to ignore the query string in the webmaster tools


(Kane York) #10

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.


(Spooky) #11

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.


(Vinoth Kannan) #12

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>

"Share a link" for a post should not leak username
(Spooky) #13

Appreciate it a lot @vinothkannans


(Vinoth Kannan) #14

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.


(Spooky) #15

Tell me, in the admin you can see who shared the posts, that’s the idea behind the query string?


(Vinoth Kannan) #16

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.


(Rafael dos Santos Silva) #17

And you lose the share related badges…