PHP wrapper for Compete API.
Wrapper has generic method get
. You can retrieve any kind of metric via this method:
<?php
require 'Compete.php';
// Create API wrapper instance
$compete = new Compete('YOUR_API_KEY');
// Basic usage
$data = $compete->get('SOME_DOMAIN', 'METRIC_CODE');
// Get the number of people who visited a domain
$data = $compete->get('facebook.com', 'uv');
// Get the ranking of the domain by total number of unique visitors
$data = $compete->get('google.com', 'rank');
Here is list of available metrics:
Metric Name | Basic or All-Acces? | description | metric code |
Unique Visitors | Basic | The number of people who visited a domain | uv |
Visits | Basic | The number of separate visits made to a domain by all unique visitors | vis |
Rank | Basic | The ranking of the domain by total number of unique visitors | rank |
Page Views | All-Access | The number of times a page has been loaded from a domain | pv |
Average Stay | All-Access | The average number of seconds that a visit lasts | avgstay |
Visits/Person | All-Access | The average number of times each unique visitor visits the domain | vpp |
Pages/Visit | All-Access | The average number of pages displayed during a visit | ppv |
Attention | All-Access | The percent of total minutes spent by all US users on the internet that were spent on this domain | att |
Reach (daily) | All-Access | The percent of all US users on the internet that had at least one visit to this domain by day | reachd |
Attention (daily) | All-Access | The percent of total minutes spent by all US users on the internet that were spent on this domain by day | attd |
Gender | All-Access | The split between males and females visiting a domain | gen |
Age | All-Access | Percent of unique visitors in various age brackets | age |
Income | All-Access | Percent of unique visitors in various income brackets | inc |
Also you can use specific methods for getting data:
<?php
// The number of people who visited a domain
$compete->uniqueVisitors('example.com');
// The number of separate visits made to a domain by all unique visitors
$compete->visits('example.com');
// The ranking of the domain by total number of unique visitors
$compete->rank('example.com');
// The number of times a page has been loaded from a domain
$compete->pageViews('example.com');
// The average number of seconds that a visit lasts
$compete->averageStay('example.com');
// The average number of times each unique visitor visits the domain
$compete->visitsPerson('example.com');
// The average number of pages displayed during a visit
$compete->pagesVisit('example.com');
// The percent of total minutes spent by all US users
// on the internet that were spent on this domain
$compete->attention('example.com');
// The percent of all US users on the internet that
// had at least one visit to this domain by day
$compete->dailyReach('example.com');
// The percent of total minutes spent by all US users
// on the internet that were spent on this domain by day
$compete->dailyAttention('example.com');
// The split between males and females visiting a domain
$compete->gender('example.com');
// Percent of unique visitors in various age brackets
$compete->age('example.com');
// Percent of unique visitors in various income brackets
$compete->income('example.com');
Return values have same format but decoded via json_decode
(wrapped in stdClass
).
Trends field name depends on specific metric.
{
"status": "OK",
"data": {
"trends": {
"uv": [
{"date": "200906", "value": 90714948},
{"date": "200907", "value": 98292793},
{"date": "200908", "value": 103509116},
...
]
},
"trends_low_sample": false,
"query_cost": 13,
"trends_frequency": "monthly"
}
}
If there is some error in request wrapper will throw CompeteException
.
- Add support for additional request params(date, graph, ...)