Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Twitter API: Tracking Tweets using Web Intents

Twitter API: Tracking Tweets using Web Intents

2

Following on from my earlier tutorial on Tweet Button Callbacks, I’ve expanded on how you can track tweets on your website or application using Web Intents and the Twitter API. With a few lines of JavaScript code, you can update your website to capture tweets and then expand this to save the information somewhere, like incrementing a counter in your database.

You can customise the tweet button anyway you like – in my example, I’ve created a simple Tweet link and a image link to demonstrate this. Including the twitter JavaScript library on your page and binding a callback to the tweet event will then allow your page to ‘listen’ out for tweets.

Sample Code:

The sample code below shows just how easy it is to listen for the tweet event:

The sample code includes two examples of twitter buttons you can create: one with just text, and one with a link and text. You can add other options to the tweet buttons too, like replies and retweets. A full list of supported parameters can be found here.

Tweet Using Web Intents

Demo:

You can see a (slightly modified) working example of the code on jsbin.com. This modified version displays a JavaScript alert popup when a tweet from the page is detected, but you can also keep your JavaScript console option to see a log of what is returned by Twitter when a user tweets.

JavaScript, Tracking, Twitter, Twitter API

2 comments on “Twitter API: Tracking Tweets using Web Intents”

  1. Toni says:
    February 7, 2014 at 7:54 AM

    Nice – but have you tried it in Internet Explorer?
    It doesnt fire the “twttr.events.bind(‘tweet’, function( event ) {“.
    Any other Browser works.

    Reply
    • Niraj Shah says:
      February 7, 2014 at 3:34 PM

      Which version of IE did you try this on?

      Reply

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bash Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Flash Geolocation Google Nexus 5 Hacking HTML5 Input Sanitization iOS JavaScript jQuery Laravel 5 Laravel 5.2 Linux Mac OS NodeJS Parse PDF PHP Plugin Portfolio Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy