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.
- Create a new facebook application. You will need an app ID before you can create the facebook like button.
- Go to the facebook developers website and create a like button:
http://developers.facebook.com/docs/reference/plugins/like/ - Choose the desired settings in the new Facebook like button form and hit the get code button
- A pop up appears. You will have to choose the XFBML option and you are going to get something like in the following snapshot:
- Follow the instructions on screen (Steps 1 and 2)
- 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>