wiki:API_1.0

FireStats API

This is for historical reference, please use the latest version of the API

As of version 1.0.0, FireStats provide several API calls that allow you to access statistics and other FireStats resources.
At the moment, the API is officially supported only under Wordpress. (if you would like support for other platform please submit an enhancment request).
However, if you feel like hacking, the APIs are defined in the file php/api.php.

if the API file is included, 'FS_API' is defined. this allow you to test if its safe to call FireStats API functions like this:

<?php
if (defined('FS_API')) 
{
   // call API here.
}
?>

The following APIs are supported:

<?php
/*
    Returns the number of pages displayed in the specified time period.
    days_ago is an optional parameter which specifies how many days ago to start counting.
    if days_ago is not specified, the count will begin when you installed FireStats.
*/
function fs_api_get_hit_count($days_ago = NULL);

/*
    Returns the number of unique hits in the specified time period.
    days_ago is an optional parameter which specifies how many days ago to start counting.
    if days_ago is not specified, the count will begin when you installed FireStats.
*/
function fs_api_get_unique_hit_count($days_ago = NULL);

/*
    Returns image tags of images representing the useragent
    3 Icons may be returned:
    * OS Icon
    * Browser Icon
    * PDA Icon (if the useagent is of a phone)

    To access the user agent of the current user in PHP use $_SERVER['HTTP_USER_AGENT']
*/
function fs_api_get_browser_and_os_images($useragent);


/*
    Returns an image tag with the flag of the country this ip_address blonged to.
    if unknown, an empty string is returned.
*/
function fs_api_get_country_flag_image($ip_address);

/*
    Returns a two characters country code of the country this ip address is belonged to.
    if unknown, false is returned.
*/
function fs_api_get_country_code($ip_address);

?>

Example

Here is an example usage of the FireStats API.

<?php
if (defined('FS_API'))
{
    echo "Hit count ever : ".fs_api_get_hit_count()."<BR/>";
    echo "Hit count in last day : ".fs_api_get_hit_count(1)."<BR/>";
    echo "Your browser and OS icons are :". fs_api_get_browser_and_os_images($_SERVER['HTTP_USER_AGENT'])."<BR/>";
    echo "Your country flag is : " .fs_api_get_country_flag_image($_SERVER['REMOTE_ADDR'])."<BR/>";
}
?>
Last modified 10 years ago Last modified on Jul 11, 2007, 8:06:14 PM