Basically I have a blog that I want to show the number of unique views for each post if you are logged in as an admin (I need it to calculate statistics that I can't do just looking at the regular GA admin).
So for the input it would be series of URL paths.
For example, if you're an admin looking at page 3 of the posts from a few days ago, and theres 10 posts per page, it would be 10 input paths.
Like such...
input:
'/hello-world/'
'/this-demo-post/'
'/woot/'
Then it would output something somewhat like this, where the array value is the number of unique visitors:
[0] => 1003,
[1] => 140,
[2] => 7761
At this point I would just output that in JSON on the page, and then use JS to make my calculations next to each post.
The tricky part is how to get this information from GA, as its seems to just pull in ALL of the data. Even if I limit the date to 3 days old, it still pulls all the data of way older posts that are still getting a lot of traffic. It clutters the results and may even possibly 'push out' some posts I want to see if it doesn't fit within the result scope.
I was thinking of maybe using filter regex with a lot of (this|or|that) on the 10 paths?
Here is what I have so far.
require 'gapi.class.php';
date_default_timezone_set('America/New_York');
$dimensions = array('pagePath');
$metrics = array('uniquePageviews'); // visits
$sortMetric = null;
$filter = null;
$startDate = date('Y-m-d', strtotime('-2 days'));
$endDate = date('Y-m-d');
$startIndex = 1;
$maxResults = 10000;
$ga = new gapi($gaEmail, $gaPassword);
$ga->requestReportData($profileId, $dimensions, $metrics, $sortMetric, $filter, $startDate, $endDate, $startIndex, $maxResults);
Edit In retrospect, this would all be solved with a way to sort by 'first seen' and not just by total views. Is this in GAPI?