Using Custom Social Bookmark Icons With AddThis Analytics

by Jon Bishop on May 12, 2009

in How To, Web Development

AddThis

(Note: This code is meant to be put in your Wordpress Template. However, it should be easy to modify it for other uses.)

Awhile back, I tweeted about how I wasn’t a huge fan of the AddThis button and I felt the need for more actionable social sharing buttons. That led to a few conversations with an AddThis representative about how I could still use their JavaScript to help track my custom buttons usage.

So now, with this code, you can use any custom social bookmarklet you like, and still track the button usage.

So first and foremost you will need an AddThis account.

Then you need to add the AddThis javascript to your HTML. I like to put it in the footer so all of my content can load first.

  1. <script type="text/javascript" src="http://s7.addthis.com/js/200/addthis_widget.js"></script>

Next, you will need to add the following javascript, substituting the “YOUR-ACCOUNT-ID” with your AddThis username. I usually put this right above the first link that will be using the AddThis code.

  1. <script type="text/javascript">
  2. addthis_title = '<?=get_the_title($id); ?>';
  3. addthis_url = '<?=get_permalink(); ?>';
  4. addthis_id = 'YOUR-ACCOUNT-ID';
  5. addthis_clickout= true;
  6. </script>

Finally you will need to add the ‘onclick’ javascript to the anchor tag like I do in the example below. The key here is to put the name of the service you wish the button to link to where I have inserted ’stumbleupon’ below. A full list of services can be found on the AddThis custom services page.

  1. <a onclick="return addthis_invoke('stumbleupon', addthis_url, addthis_title, addthis_id);" href="http://www.stumbleupon.com/submit?url=<?=get_permalink(); ?>%26title%3D<?=get_the_title($id); ?>"><img border=0 src="http://cdn.stumble-upon.com/images/160×30_su_blue.gif"></a>

So that is how I am able to track my sharing button usage on my site through AddThis without using the AddThis button.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

{ 1 comment… read it below or add one }

Justin Thorp May 16, 2009 at 12:51 pm

Glad to hear that you’re still enjoying our services. Let us know if there is anything else we can do to improve. – justin@addthis.com

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Send To Twitter What's CommenTwitter?

Previous post: How Much Value Is In A ReTweet?

Next post: What We Can Learn From Drive-Through Menus