Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [119]

By Root 771 0
day (e.g., two calls to fql_query would count as two here).

unique_api_calls

int

Unique API calls made by your app on this day (e.g., two calls to fql_query would count as only one here).

canvas_page_views

int

Number of Canvas pages your app served up on this day (two views of the same page count as two views here).

unique_canvas_page_views

int

Unique number of Canvas pages your app served up on this day (two views of the same page count as only one views here).

canvas_http_request_time_avg

int

The average time required to handle an HTTP request from your app, in milliseconds.

canvas_fbml_render_time_avg

int

The average time required to render an FBML page for your app, in milliseconds.

canvas_page_views_http_code_0

int

The number of Canvas pages that timed out.

canvas_page_views_http_code_200

int

The number of Canvas page requests that were successful (HTTP code 200 is success).

canvas_page_views_http_code_200ND

int

The number of Canvas page requests that were successful but returned no data (HTTP code 200 is success; ND is no data).

canvas_page_views_http_code_404

int

The number of Canvas page requests that couldn’t be found (HTTP code 404 is resource not found).

Note that only the fields marked as “Index” in this table can be used in an FQL query’s WHERE clause, but any of the fields can appear in the SELECT.

Discussion


If you’d rather use the API to access metrics, try the Admin.getMetrics() method.

This table actually contains fields for every HTTP code, not just the ones listed here. Simply sub in the code you want and you should get results. For example, if you were looking for 301, which is “resource permanently moved,” you could SELECT canvas_page_views_http_code_301.

Retrieving Yesterday’s Metrics


Problem


I need to retrieve some of my metrics from yesterday.

Solution


Since the date field is in epoch seconds, you need to do a conversion before you can query on it:

$hoursAhead = 3;

$period = 86400; // 86400 = one day, 604800 = one week, 2592000 = one month

$yesterday = mktime($hoursAhead,0,0,date("m"),date("d")-1,date("Y"));

$monthAgo = mktime($hoursAhead,0,0,date("m"),date("d")-30,date("Y"));

$query = 'SELECT api_calls from metrics WHERE end_time = ' .

$yesterday . ' AND period = ' . $period . ';';

$metrics = $facebook->api_client->fql_query($query);

?>

You’ll need to substitute the number of hours that your server’s time zone is ahead of PST into the first line, and also change the fields you want to retrieve in the actual query if you want something other than just the number of API calls.

Discussion


The hours ahead of PST is important because Facebook calculates metrics at midnight PST and considers a day from midnight to 11:59:59 p.m. PST. You should always set your date ranges based on that time zone. See Formatting Relative Time for more information about epoch seconds.

Retrieving Metrics for a Date Range


Problem


I need to retrieve some of my app’s metrics for the last 30 days.

Solution


Since the date field is in epoch seconds, you need to do a conversion before you can query on it:

$hoursAhead = 3;

$period = 2592000; // 86400 = one day, 604800 = one week, 2592000 = one month

$yesterday = mktime($hoursAhead,0,0,date("m"),date("d")-1,date("Y"));

$monthAgo = mktime($hoursAhead,0,0,date("m"),date("d")-30,date("Y"));

$query = 'SELECT active_users from metrics WHERE end_time = ' .

$yesterday . ' AND period = ' . $period . ';';

$metrics = $facebook->api_client->fql_query($query);

?>

The variable metrics will now contain an array with a single element that contains the active_users for the 30-day period ending yesterday.

Discussion


The hours ahead of PST is important because Facebook calculates metrics at midnight PST and considers a day from midnight to 11:59:59 p.m. PST. You should always set your date ranges based on that time zone. See Formatting Relative Time for more information about epoch seconds.

Alerting Yourself


Problem


I’d like to receive email alerts when

Return Main Page Previous Page Next Page

®Online Book Reader