I´me us开发者_JS百科ing GAPI (Google Analytics PHP Interface) to get the most searched keywords in my website. This code works ok
$ga->requestReportData(id, array('searchKeyword'), array('searchUniques'),array('-searchUniques'),null,null,null,1,12 );
foreach($ga->getResults() as $result)
{
echo ' '. $result .' '.$result->getSearchUniques().'<br/> ' ;
}
But I would like the output to be written on a file....
$fp = fopen('results.txt', 'w');
$ga->requestReportData(id, array('searchKeyword'), array('searchUniques'),array('-searchUniques'),null,null,null,1,12 );
foreach($ga->getResults() as $result)
{
fwrite($fp, " ". $result ." ".$result->getSearchUniques()."\n");
}
fclose($fp);
Don't forget to create a file named results.txt
(or whatever name you want) and chmod it to 777.
$savefile='/your/dir/to/use/ga.txt';
$fh=fopen();
foreach($ga->getResults() as $result)
{
$line_to_save = ' '. $result .' '.$result->getSearchUniques()."\n";
fputs($fh,$line_to_save);
}
fclose($fh);
精彩评论