TraceWatch Website Statistics

GetStats API

The GetStats API is a set of simple functions that let you fetch stats data like number of online visitors, page views, unique visitors, etc... from database to show on your website pages.

To use the GetStats API functions first include twatch/api/GetStats.php file on the page then call any of the functions below:

twatchOnlineVisitorsCount()

function twatchOnlineVisitorsCount( $websiteId = 1 )

Arguments

$websiteId (string)
ID of the website.

Return Value

(interger) Number of online visitors

twatchCounterResult()

function twatchCounterResult( $counterId, $periodType, $periodCode , $value = null, $group = null, $websiteId = 1 )

Arguments

$counterId (integer)

ID of the counter. Use one of these constants:

  • TwatchCounter::PAGE_VIEWS for page views
  • TwatchCounter::SESSIONS for sessions
  • TwatchCounter::VISITORS for unique visitors
  • TwatchCounter::NEW_VISITORS for new visitors
  • TwatchCounter::ROBOT_PVIEWS for robot page views
  • TwatchCounter::PAGES for pages
  • TwatchCounter::REFGROUPS for referrer groups
  • TwatchCounter::REFERRERS for referrers
  • TwatchCounter::BROWSERS for browsers
  • TwatchCounter::UA_STRINGS for user agent strings
  • TwatchCounter::DIST_HOURLY for hourly distribution
  • TwatchCounter::DIST_WEEKLY for weekday distribution
  • TwatchCounter::ROBOT for robots
$periodType (integer)

Can be one of these constants:

  • TwatchPeriod::DAY to get value for a certain day.
  • TwatchPeriod::MONTH to get value for a certain month.
  • TwatchPeriod::ALL to get the all time value.
$periodCode (string)
  • "yymmdd" when $periodType is DAY. e.g. "090124" for January 24th 2009. You can also use twatchToday() and twatchYesterday() functions to get code for today and yesterday respectively. (these functions use TraceWatch's time-zone)
  • "yymm" when $periodType is MONTH. e.g. "0901" for January 2009. ou can also use twatchThisMonth() and twatchLastMonth() functions to get code for this month and last month respectively. (these functions use TraceWatch's time-zone)
  • "" (empty string) when $periodType is ALL
$value (string)
For list counters and grouped counters you should specify one value from the list to get. e.g. for TwatchCounter::PAGES counter setting $value to "/products/pc.php" gives you /products/pc.php hits
$group (string)
For grouped counters like TwatchCounter::REFERRERS you must specify the group as well as $value.
$websiteId (string)
ID of the website

Return Value

  • (Integer) Counter hits.

Some Examples

  • twatchCounterResult( TwatchCounter::VISITORS, TwatchPeriod::DAY, twatchToday() ) returns number of today's unique visitors.
  • twatchCounterResult( TwatchCounter::SESSIONS, TwatchPeriod::MONTH, twatchLastMonth() ) returns number of last month's sessions.
  • twatchCounterResult( TwatchCounter::PAGES, TwatchPeriod::DAY, "090223", "/products.php" ) number of /products.php hits on February 23rd 2009.

[NOTE] you can use ardeRequestUri() or ardeRemoveUrlParams( ardeRequestUri() ) to get url of the current page with or without parameters respectively to use as the value for TwatchCounter::PAGES counter.

Current Version: 0.353

Support TraceWatch Web Stats
Flattr this