Updated implementation on how to execute JavaScript on Facebook like clicks

In a previous post I described how to execute Javascript source code when the facebook button is clickedu using XFBML. A long time has passed since then and facebook has changed the way the like button is deployed using XFBML.

Find below the updated and easier way to implement JavaScript tagging when someone clicks the Like button:

The steps below are mentioned with few details. You can check the previous article for a more detailed desription.

    1. Create a new facebook application. You will need an app ID before you can create the facebook like button.
    2. Go to the facebook developers website and create a like button:
      http://developers.facebook.com/docs/reference/plugins/like/
    3.  Choose the desired settings in the new Facebook like button form and hit the get code button
    4. A pop up appears. You will have to choose the XFBML option and you are going to get something like in the following snapshot:

    5. Follow the instructions on screen (Steps 1 and 2)
    6. Copy the source code from step 3 and just add the JavaScript source code that needs to be executed on the onClick event of the fb:like, like in the following sample:
      <fb:like onclick="javascript: _gaq.push(['_trackPageview', 'example.com/facebook']);" href="http://www.example.com/" ><fb:like>

Written By

Panagiotis (pronounced Panayotis) is a passionate G(r)eek with experience in digital analytics projects and website implementation. Fan of clear and effective processes, automation of tasks and problem-solving technical hacks. Hands-on experience with projects ranging from small to enterprise-level companies, starting from the communication with the customers and ending with the transformation of business requirements to the final deliverable.