Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
Version 0.6.4 Beta
Browse files Browse the repository at this point in the history
Advancement on @skl's code update. Ensure if the user wants to ignore
bots then the bots list is not empty, if it is then it's a
RuntimeException
  • Loading branch information
Tom Chapman authored and Tom Chapman committed Dec 14, 2011
1 parent d246f19 commit dd70ea8
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions GoogleAnalyticsServerSide.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GPL
* @author Tom Chapman
* @link http://github.com/chappy84/google-analytics-server-side
* @version 0.6.3 Beta
* @version 0.6.4 Beta
* @example $gass = new GoogleAnalyticsServerSide();
* $gass->setAccount('UA-XXXXXXX-X')
* ->createPageView();
Expand Down Expand Up @@ -76,7 +76,7 @@ class GoogleAnalyticsServerSide {
* @var string
* @access private
*/
private $version = '5.1.0';
private $version = '5.2.2';


/**
Expand Down Expand Up @@ -170,7 +170,7 @@ class GoogleAnalyticsServerSide {
* @access private
*/
private $charset = 'UTF-8';


/**
* Whether or not to send the cookies when send
Expand Down Expand Up @@ -901,8 +901,8 @@ private function getCookie($name) {
}
throw new OutOfBoundsException('Cookie by name: '.$name.' is not related to Google Analytics.');
}


/**
* Disables whether or not the cookie headers are sent when setCookies is called
*
Expand All @@ -925,10 +925,12 @@ private function setBotsFromCsv() {
$this->setBotsCacheDate();
if (null !== ($lastCacheDate = $this->getBotsCacheDate())) {
$csvPath = $csvPathname.DIRECTORY_SEPARATOR.$this->getOption('cacheBotsFilename');
if ($lastCacheDate > (time() - $this->getOption('cacheTimeout')) && is_readable($csvPath)) {
$botsCsv = file_get_contents($csvPath);
} elseif (false === @unlink($csvPath)) {
throw new RuntimeException('Cannot delete "'.$csvPath.'". Please check permissions.');
if ($lastCacheDate < (time() - $this->getOption('cacheTimeout')) || !is_readable($csvPath)
|| false === ($botsCsv = file_get_contents($csvPath)) || '' == trim($botsCsv)) {
unset($botsCsv);
if (false === @unlink($csvPath)) {
throw new RuntimeException('Cannot delete "'.$csvPath.'". Please check permissions.');
}
}
}
}
Expand All @@ -948,7 +950,12 @@ private function setBotsFromCsv() {
* @access private
*/
private function retreiveBotsCsv() {
return trim($this->getSource(self::BOT_CSV_LOCATION));
$botsCsv = trim($this->getSource(self::BOT_CSV_LOCATION));
if (empty($botsCsv)) {
throw new RuntimeException( 'Bots CSV retrieved from external source seems to be empty. '
.'Please either set ignoreBots to false or ensure the bots csv file can be retreived.');
}
return $botsCsv;
}


Expand All @@ -963,7 +970,7 @@ private function parseBotsCsv($fileContexts) {
$botList = explode("\n", $fileContexts);
$distinctBots = array();
foreach ($botList as $line) {
if ( !empty($line)) {
if (!empty($line)) {
$csvLine = str_getcsv($line);
if (!isset($distinctBots[$csvLine[0]])) {
$distinctBots[$csvLine[0]] = (isset($csvLine[6])) ? $csvLine[6] : $csvLine[1];
Expand Down

0 comments on commit dd70ea8

Please sign in to comment.