AddThis Issue with 2 Tweet Buttons on Page | twttr.events.bind not firing | WordPress


#1

I’m testing a application that I custom building. So the tweet button will show within the contents of a post or page. But AddThis also adds a tweet button at the bottom or each post / page.

If I do NOT have AddThis show (with tweet button) on the WordPress page the twttr.events.bind follow & tweet twttr.events.bind events fire just fine.
But when I have the AddThis appear on a page it doesn’t work anymore. The tweet pop-up box opens and tweets just fine but the twtter.events.bind never fires.

I tried to remove this when AddThis is enabled for the page. Just in case it was being loaded twice but still the same issue.

<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>

BUT if I have AddThis enabled for the page and NOT have the tweet button show up so the tweet button I’ve created shows within the content of the post / page it works… So the issue is when there are 2 tweet buttons. One from me within the content and another from AddThis at the end of the post / page.

Any ideas?

Here is the full code:

				<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>				
				<script type="text/javascript">
				twttr.events.bind('tweet', function(event) {
					alert("Twitter Lottery Entry Successful");
				});
				twttr.events.bind('follow', function(event) {
					document.getElementById("twitterStep1").style.display = "none";
					document.getElementById("twitterStep2").style.display = "block";
				});
				</script>

                               <a href="http://twitter.com/share" class="twitter-share-button" 
				data-url="'.$cb_tweet_lottery1_url.'"
				data-text="'.$cb_tweet_lottery1_txt.'"
				data-count="none">Tweet</a>

And here is the code that AddThis adds:

<!-- AddThis Button BEGIN -->
<script type="text/javascript">
//<!--
var addthis_product = 'wpp-250';

//-->
</script>
<div class="addthis_container addthis_toolbox addthis_default_style" addthis:url="http://www.mysite.net/lottery-1/" addthis:title="Lottery 1"><a href="http://www.addthis.com/bookmark.php?v=250&amp;username=ps3blogdotnet" class="addthis_button_compact"></a><a class="addthis_button_tweet"></a><a class="addthis_button_facebook_like"></a><a class="addthis_button_google_plusone"></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=ps3blogdotnet"></script></div>
<!-- AddThis Button END -->

#2

Can you post the code which AddThis is inserting into your page? I tried to reproduce your error by including two separate event listeners on a page, but both callbacks fired correctly…


#3

Thank you for the reply. I updated the original post with that code.


#4

Thanks, unfortunately it appears that it’s really the AddThis file at http://s7.addthis.com/js/250/addthis_widget.js#username=ps3blogdotnet which is breaking events (if you don’t use AddThis and add two “tweet” event listeners, both get called, so the code on Twitter’s end should be working).

Since their code is compacted, it’s really difficult for me to try and figure out what they might be doing to break the events system. Have you contacted them to ask about this issue?


#5

Thanks for the reply. I actually did another test where my application and a regular follow button in the sidebar showed up. The event listeners don’t fire … no addThis on the page that time.

So seems like anything with 2 tweets or 2 follow buttons breaks it.

This is my twitter follow button in the sidebar:

Follow @ps3blogdotnet

#6

Any ideas why?


#7

This was the use case I tested - the following code did trigger events:

Tweet Tweet more Follow

Perhaps you left the AddThis script include in your source?


#8

Not sure if I mentioned this was in WordPress. The follow button I had was in the sidebar. But I had AddThis disabled to show on pages. So no addthis sharing showed up. But didn’t work.

But if I removed the sidebar and added another follow button or have 2 tweet buttons. It DOES work … mm

I search for references of AddThis in the source when I had the sidebar showing but nothing… so not sure why it’s still breaking. So weird…


#9
2. 11. 12. Tweet

#10

What worked for me is renaming the addthis_toolbox classes different. So, for one of them I left it alone as addthis_toolbox and the second one I simply added a 2 like this addthis_toolbox2. Might be something as small as that and simple, but it helped me out. Hope it helps.


#11