Return Facebook Insight Data for Domain using JavaScript

1.2k Views Asked by At

I'm looking for a very simple "hello world" type of example that will help me understand how to use JavaScript to retrieve the Insight data for my domain.

I want to return the total number of Likes (domain_like_adds) for the day on my website, but I'm not sure how to go about it. The Facebook documentation has me running in circles.

Thanks for your help!

1

There are 1 best solutions below

5
On

See this page for more information on how to define your query:

http://developers.facebook.com/docs/reference/fql/insights/

Here's the basic query and facebook JS API query with callback function:

var insight_domain = "http://www.mydomain.com";

var insight_query = "SELECT metric, value FROM insights where metric="domain_like_adds" AND end_time=end_time_date('2011-04-06')  AND period=period('day') AND object_id in (select id from object_url where url ='{0}')";

var query = FB.Data.query(insight_query, insight_domain);
query.wait(function(data) {
  //process your insight data here
});