Independent Analytics includes a simple developer API for anyone who wants to access their data outside of the analytics dashboard.
As of now, the API includes two simple functions, as documented below.
iawp_analytics(DateTime $from, DateTime $to)
Gets analytics data from the given date range. Includes views, visitors, and sessions.
Parameters
- $from
- Type: DateTime
- Required
- Description: This is the starting date for your selected date range.
- $to
- Type: DateTime
- Required
- Description: This is the ending date for your selected date range.
Return
Returns an IAWP\Public_API\Analytics object with three properties: views, visitors, and sessions.
IAWP\Public_API\Analytics { views: 800, visitors: 325, sessions: 355 }
Example
Here’s how you would get data from the past three days and output the number of views:
$analytics = iawp_analytics(new DateTime('-3 days'), new DateTime());
echo $analytics->views;
iawp_singular_analytics(int $singular_id, DateTime $from, DateTime $to)
Gets analytics data from the given date range for a specific page. Includes views, visitors, and sessions.
Parameters
- $singular_id
- Type: int
- Required
- Description: This is the ID of the page you want to get stats for.
- $from
- Type: DateTime
- Required
- Description: This is the starting date for your selected date range.
- $to
- Type: DateTime
- Required
- Description: This is the ending date for your selected date range.
Return
Returns an IAWP\Public_API\Singular_Analytics object with the three properties: views, visitors, and sessions.
IAWP\Public_API\Singular_Analytics { views: 400, visitors: 125, sessions: 255 }
Example
Here’s how you would get data from the last seven days for a page with an ID of “60” and output the sessions:
$singular_analytics = iawp_singular_analytics(60, new DateTime('-7 days'), new DateTime());
echo $singular_analytics->sessions;