# Twitter shared URL has a query string

**URL:** https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446
**Category:** Support
**Created:** [July 18, 2016, 6:10am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446 "2016-07-18T06:10:38Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Idan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/idan/32/198212_2.png) [@Idan](https://meta.discourse.org/u/Idan)
#### Post date: [July 18, 2016, 6:10am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/1 "2016-07-18T06:10:38Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [July 18, 2016, 7:38am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/2 "2016-07-18T07:38:35Z")

</div>

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

> [@Usernames in shared links break anonymity](https://meta.discourse.org/t/unencrypted-usernames-in-shared-links-break-anonymity/42554/9):
>
> I am fine with that as a PR, but you would automatically lose all the sharing badges (first share, nice share, good share, great share) if you disabled usernames there.

---

<div class="post-metadata">

### Author: ![Idan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/idan/32/198212_2.png) [@Idan](https://meta.discourse.org/u/Idan)
#### Post date: [July 18, 2016, 7:51am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/3 "2016-07-18T07:51:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [July 18, 2016, 7:59am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/4 "2016-07-18T07:59:21Z")

</div>

[quote="Idan, post:3, topic:47446]  
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  
[/quote]

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.

[quote="Idan, post:3, topic:47446]  
and send to the server via webservice, instead of doing t on the server by reading the query string.  
[/quote]

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.

[quote="Idan, post:3, topic:47446]  
And regarding the link to the post, you better off using the userId, not the username.  
[/quote]

Why?

---

<div class="post-metadata">

### Author: ![johnmuhl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johnmuhl/32/43413_2.png) [@johnmuhl](https://meta.discourse.org/u/johnmuhl)
#### Post date: [July 20, 2016, 1:11am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/5 "2016-07-20T01:11:00Z")

</div>

> [@mpalmer](#):
>
> 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.

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

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [July 20, 2016, 1:20am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/6 "2016-07-20T01:20:07Z")

</div>

> [@johnmuhl](#):
>
> It is part of Google’s documentation on using canonical URLs.

Is this documentation available on the Internet?

---

<div class="post-metadata">

### Author: ![Idan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/idan/32/198212_2.png) [@Idan](https://meta.discourse.org/u/Idan)
#### Post date: [July 20, 2016, 1:24am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/7 "2016-07-20T01:24:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [July 20, 2016, 2:02am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/8 "2016-07-20T02:02:30Z")

</div>

> [@mpalmer](#):
>
> It is part of Google’s documentation on using canonical URLs.

> [@mpalmer](#):
>
> Is this documentation available on the Internet?

Here:

> **[How to Specify a Canonical with rel="canonical" and Other Methods | Google...](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls?hl=en&visit_id=639159006115716940-22142312&rd=1)**
>
> When a site has duplicate content, Google chooses the canonical URL. Learn more about canonical URLs and how to consolidate duplicate URLs.

---

<div class="post-metadata">

### Author: ![Idan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/idan/32/198212_2.png) [@Idan](https://meta.discourse.org/u/Idan)
#### Post date: [July 20, 2016, 2:04am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/9 "2016-07-20T02:04:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [July 20, 2016, 6:08am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/10 "2016-07-20T06:08:14Z")

</div>

> [@mpalmer](#):
>
> 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.

> [@johnmuhl](#):
>
> It is part of Google’s documentation on using canonical URLs.

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.

---

<div class="post-metadata">

### Author: ![Idan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/idan/32/198212_2.png) [@Idan](https://meta.discourse.org/u/Idan)
#### Post date: [July 20, 2016, 6:20am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/11 "2016-07-20T06:20:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [July 20, 2016, 6:47am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/12 "2016-07-20T06:47:00Z")

</div>

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>

```

---

<div class="post-metadata">

### Author: ![Idan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/idan/32/198212_2.png) [@Idan](https://meta.discourse.org/u/Idan)
#### Post date: [July 20, 2016, 7:02am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/13 "2016-07-20T07:02:48Z")

</div>

Appreciate it a lot @vinothkannans

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [July 20, 2016, 7:24am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/14 "2016-07-20T07:24:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Idan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/idan/32/198212_2.png) [@Idan](https://meta.discourse.org/u/Idan)
#### Post date: [July 20, 2016, 7:30am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/15 "2016-07-20T07:30:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [July 20, 2016, 7:44am UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/16 "2016-07-20T07:44:44Z")

</div>

> [@Idan](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 20, 2016, 1:23pm UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/17 "2016-07-20T13:23:19Z")

</div>

And you lose the share related badges…

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:45pm UTC](https://meta.discourse.org/t/twitter-shared-url-has-a-query-string/47446/18 "2024-06-08T12:45:24Z")

</div>

This topic was automatically closed after 2882 days. New replies are no longer allowed.
