This is how I am getting the pageviews of a url for a custom interval (usually the date of creation of the url and the present)
$ga->requestReportData(
$ga_profile_id,
array('date'),
array('pageviews'),
'date',
'pagePath == '.$ga_url,
$ga_start, /* Creaton day */
date("Y-m-d", strtotime("0 day", time())), /* Today */
null,
1000
);
$results = $ga->getResults();
The thing is that some of the urls are old and then my chart looks too saturated:
So I would like to check the value of the interval in days, and if its big enough; get the pageviews by weeks (and then if its big enough, maybe in months?)
Is it posible?
This is how I am generating the Chart, by the way:
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
<!-- Create the data table -->
data.addColumn('string', 'Day');
data.addColumn('number', 'Lecturas');
<!-- Fill the chart with the data pulled from Analtyics. Each row matches the order setup by the columns: day then pageviews -->
data.addRows([
<?php
foreach($results as $result) {
echo '["'.date('M j',strtotime($result->getDate())).'", '.$result->getPageviews().'],';
}
?>
]);
var chart = new google.visualization.AreaChart(document.getElementById('chart'));
chart.draw(data, {width: 630, height: 180, title: '<?php echo $ga_start.' - '. date("Y-m-d", strtotime("0 day", time())); ?>',
colors:['#999999','#ff0000'],
areaOpacity: 0.1,
hAxis: {textPosition: 'in', showTextEvery: 30, slantedText: false, textStyle: { color: '#555555', fontSize: 10 } },
pointSize: 5,
legend: 'none',
chartArea:{left:0,top:30,width:"100%",height:"100%"}
});