Tweet Button - how to include query string with URL?


#1

How do I get the Tweet button include the full URL of the current page, including the query string? E.g. www.myexample.com/category/page?v=0&num=123

The default code from Twitter (https://dev.twitter.com/web/tweet-button/parameters) works on my site, except it only provides the first part, e.g. www.myexample.com/category/page

I have quite a few pages* on one section of my site that are populated with varying content from a database, depending on the values in the query string, so it’s critical the share links have the query string or else the page is devoid of content.

After a couple hours of fruitless effort trying to get this to work I figured I ask for some help. If anybody needs me to provide additional info let me know.

*It’s really just one page with dynamic content, and thus only one Tweet button.


#2

You should be URL encoding the passed URL. Example:
http://jsfiddle.net/y0w47924/

If you do not pass an explicit URL parameter the link canonical of the page may be used.


#3

Thanks for the reply.

Unless I’m misunderstanding (very possible), the method you showed via jsfiddle is something that would have to be set manually, for every page, correct? If so, I don’t think that will work, because I have over 50 versions of a single page, where the version/content is determined by the query string (it pulls a bunch of info from a database).

Based on some additional research it looks like I’ll probably have to use some JavaScript in order for it to recognize the full URL.


#4

If you vary the content of a page based on a query parameter then you will want to set the canonical link of the page to make sure references to the page are accurately captured and extra query parameters with no effect are collapsed.
https://support.google.com/webmasters/answer/139066

Passing a URL parameter to the Tweet intent is the best way to explicitly define the URL you would like a viewer to share.


#5