20

I am using the official Tweet Button from Twitter to allow users to share my site.

The button itself is working just fine, however the counter doesn't work and stays at zero all the time. (after you tweet, it is incremented client-side, but if you press F5, it will be zero again)

This is my really simple code to include the button:

<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.whattheplace.com/Show/1/" data-count="vertical">Tweet</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>

The specified URL (http://www.whattheplace.com/Show/1/) is a regular URL returning a web page with HTTP code 200, i.e. no redirection or the like that could maybe confuse Twitter.

I've prepared a small example on http://www.whattheplace.com/static/tweetbutton.html where you can see the problem. On the "real" page at http://www.whattheplace.com, the Tweet Button is wrapped by AddThis, but the problem is exactly the same.

I'm thinking that it might have something to do with the new Twitter URL shortener (t.co), however I can't prove it and it seems to work on other people's pages just fine.

7 Answers 7

15

There are a few possible problems related to this. One of them is that if the link is shortened, Twitter won't add it up unless you add the "counturl" url property.

Also, Twitter doesn't count the tweets coming from protected accounts (accounts that don't share their tweets).

Please let me know if none of this offers the solution.

Cheers!

1
13

Something else to bear in mind is that the tweet counts are not accurate in real time. They are cached and updated asynchronously. See http://dev.twitter.com/pages/tweet_button_faq#count-api-increment

0
2

I had luck switching from the URL parameter method to the data- attributes method.

function twtrButton(url, text, configs){
    // Create a link
    var params = {
        rel: 'canonical',
        'data-count': 'horizontal',
        href: 'http://twitter.com/share/'
    };
    if (url) {
        params['data-url'] = url;
        params['data-counturl'] = url;
    }
    if (text) {
        if(text.length > 90){
            text = text.substring(0, 90);
            text += '...';
        }
        params['data-text'] = text;
    }
    if (configs) {
        if (configs.via) {
            params['data-via'] = configs.via;
        }
        if (configs.related) {
            params['data-related'] = configs.related;
        }
    }
    var link = $('<a>', params).addClass('twitter-share-button');
    return link;
}

This snippet assumes jQuery 1.5 or greater.

1

I had this problem too and found out that it was related to the value of the "canonical" link tag I had set. It was set to http:// www.iphone4simulator.com but tweet button was sharing http://iphone4simulator.com because I had set my DNS servers to remove www string from the address. As soon as I changed the canonical URL value in the markup to the latter, the button worked like a charm!

1
  • Thanks, but this does not seem like the problem. I've prepared a new example at whattheplace.com/static/tweetbutton.html I've clicked all tweet buttons, but only the last two (the ones, pointing to a .html file) will count. I don't see what the difference between the last two and the 3rd and 4th URLs is since both are valid HTML documents without redirection (the first two URLs redirect which might be a reason why they don't work).
    – ChrisM
    Sep 28, 2010 at 14:34
1

I think you are missing data-via="#"

<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.whattheplace.com/Show/1/" data-count="vertical" data-via="#">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>

If its rapped around the add this im quite sure you should "mix" it with the twitter button itself, shouldn´t you be using something like:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=viralizate"></script>
<!-- AddThis Button END -->

I´m not finding the question clear enough, hope it helps anyway! if you explain further i will gladly edit it! - if i know the answer ;)

Good luck!

Trufa

1
  • I tried data-via but it just added a "via @#" to the tweet text which is correct in what I think it should do according to the documentation (dev.twitter.com/pages/tweet_button). But I'm afraid I don't understand your second recommendation. The problem is independend from AddThis, it happens with the raw Tweet Button, too.
    – ChrisM
    Oct 18, 2010 at 19:18
1

you must use both "data-count" AND "data-url" if you want to show a count and there is a url shortener involved (and there always is):

  data-url="http://dev.twitter.com/pages/tweet_button"
  data-count="vertical"
1

it's not data-url, since that's the shortened url... you don't have to bother including that i don't think. set data-counturl=THE_PAGES_ACTUAL_URL so irregardless of what shortener someone uses, the count for your actual url gets incremented and displayed. so something like this... data-counturl="<?php echo $_SERVER['PHP_SELF']; ?>"

--- ummm... nevermind, i spoke too soon...

1
  • 2
    This is the important part. The data-counturl property must point to the EXPANDED FINAL DESTINATION
    – Dex
    Jan 10, 2012 at 4:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.