I´me using 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.