diff --git a/core/Archive/Single.php b/core/Archive/Single.php
index be7b42867ab969e6b0162ff4492e15cd5163e6c1..bd9ffc1ff343b083da23a80f7fda7adadacf3bcd 100644
--- a/core/Archive/Single.php
+++ b/core/Archive/Single.php
@@ -76,7 +76,7 @@ class Piwik_Archive_Single extends Piwik_Archive
 	 */
 	protected $alreadyChecked = false;
 
-	public function __destruct()
+	protected function clearCache()
 	{
 		foreach($this->blobCached as $name => $blob)
 		{
@@ -85,6 +85,11 @@ class Piwik_Archive_Single extends Piwik_Archive
 		$this->blobCached = array();
 	}
 	
+	public function __destruct()
+	{
+		$this->clearCache();
+	}
+	
 	/**
 	 * Returns the pretty date of this Archive, eg. 'Thursday 20th March 2008'
 	 *
@@ -172,42 +177,55 @@ class Piwik_Archive_Single extends Piwik_Archive
 				return;
 			}
 			
-			// we make sure the archive is available for the given date
-			$periodLabel = $this->period->getLabel();
-			$archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel);
-			$archiveProcessing->setSite($this->site);
-			$archiveProcessing->setPeriod($this->period);
-			$archiveProcessing->setSegment($this->segment);
-			$archiveProcessing->setRequestedReport( $this->getRequestedReport() );
-			$idArchive = $archiveProcessing->loadArchive();
+    		// we make sure the archive is available for the given date
+    		$periodLabel = $this->period->getLabel();
+    		$this->archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel);
+    		$this->archiveProcessing->setSite($this->site);
+    		$this->archiveProcessing->setPeriod($this->period);
+    		$this->archiveProcessing->setSegment($this->segment);
+    		
+    		$this->archiveProcessing->init();
+    		
+			$this->archiveProcessing->setRequestedReport( $this->getRequestedReport() );
+		
+			$idArchive = $this->archiveProcessing->loadArchive();
 			if(empty($idArchive))
 			{
-				if($archiveProcessing->isArchivingDisabled())
+				if($this->archiveProcessing->isArchivingDisabled())
 				{
-					$archiveProcessing->isThereSomeVisits = false;
+					$this->archiveProcessing->isThereSomeVisits = false;
 				}
 				else
 				{
     				Piwik::log("$logMessage not archived yet, starting processing...");
     				$archiveJustProcessed = true;
-    				$archiveProcessing->launchArchiving();
-    				$idArchive = $archiveProcessing->getIdArchive();
+    				
+    				// Process the reports
+    				$this->archiveProcessing->launchArchiving();
+    				
+    				$idArchive = $this->archiveProcessing->getIdArchive();
 				}
 			}
 			else
 			{
 				Piwik::log("$logMessage archive already processed [id = $idArchive]...");
 			}
-			$this->archiveProcessing = $archiveProcessing;
-			$this->isThereSomeVisits = $archiveProcessing->isThereSomeVisits;
+			$this->isThereSomeVisits = $this->archiveProcessing->isThereSomeVisits;
 			$this->idArchive = $idArchive;
 		}
 		return $archiveJustProcessed;
 	}
 	
-	
 	protected $isArchivePrepared = false;
 	
+	protected function triggerProcessing()
+	{
+	    if(!$this->isArchivePrepared)
+	    {
+	        $archiveJustProcessed = $this->prepareArchive();
+    		$this->isArchivePrepared = true;
+	    }
+	}
 	/**
 	 * Returns a value from the current archive with the name = $name 
 	 * Method used by getNumeric or getBlob
@@ -219,12 +237,7 @@ class Piwik_Archive_Single extends Piwik_Archive
 	protected function get( $name, $typeValue = 'numeric' )
 	{
     	$this->setRequestedReport($name);
-    	
-	    if(!$this->isArchivePrepared)
-	    {
-	        $archiveJustProcessed = $this->prepareArchive();
-    		$this->isArchivePrepared = true;
-	    }
+    	$this->triggerProcessing();
 	    
 		// values previously "get" and now cached
 		if($typeValue == 'numeric'
@@ -353,11 +366,10 @@ class Piwik_Archive_Single extends Piwik_Archive
 	 */
 	public function preFetchBlob( $name )
 	{
-		if(!$this->isThereSomeVisits)
-		{
-			return false;
-		}
-
+    	$this->setRequestedReport($name);
+    	$this->triggerProcessing();
+    	if(!$this->isThereSomeVisits) { return; } 
+    	
 		$tableBlob = $this->archiveProcessing->getTableArchiveBlobName();
 
 		$db = Zend_Registry::get('db');
@@ -465,17 +477,17 @@ class Piwik_Archive_Single extends Piwik_Archive
 		$data = $this->get($name, 'blob');
 		
 		$table = new Piwik_DataTable();
-		
+	
 		if($data !== false)
 		{
 			$table->addRowsFromSerializedArray($data);
 		}
-		
 		if($data === false 
 			&& $idSubTable !== null)
 		{
 			// This is not expected, but somehow happens in some unknown cases and very rarely.
 			// Do not throw error in this case
+			// throw new Exception("not expected");
 			return new Piwik_DataTable();
 		}
 	
diff --git a/core/ArchiveProcessing/Day.php b/core/ArchiveProcessing/Day.php
index 2a57e7810f47001834178fd65e56e66b4601fea5..60a3d84d923b7bae2af83a9d9c27247796b07c4b 100644
--- a/core/ArchiveProcessing/Day.php
+++ b/core/ArchiveProcessing/Day.php
@@ -395,6 +395,8 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing
 	 */
 	public function getDataTableWithSubtablesFromArraysIndexedByLabel( $arrayLevel0, $subArrayLevel1ByKey )
 	{
+		$parentTableLevel0 = new Piwik_DataTable();
+		
 		$tablesByLabel = array();
 		foreach($arrayLevel0 as $label => $aAllRowsForThisLabel)
 		{
@@ -402,7 +404,6 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing
 			$table->addRowsFromArrayWithIndexLabel($aAllRowsForThisLabel);
 			$tablesByLabel[$label] = $table;
 		}
-		$parentTableLevel0 = new Piwik_DataTable();
 		$parentTableLevel0->addRowsFromArrayWithIndexLabel($subArrayLevel1ByKey, $tablesByLabel);
 
 		return $parentTableLevel0;
diff --git a/plugins/API/API.php b/plugins/API/API.php
index 995499cec693213529acd2b5063014ba58ce2711..d55cc9d70db97ee107424131d5f837d00d15ac72 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -296,11 +296,12 @@ class Piwik_API_API
 			'idSite' => $idSite,
 			'period' => $period,
 			'date' => $date,
-			'segment' => $segment,
 			'format' => 'original',
 			'serialize' => '0',
 			'language' => $language,
 		));
+		if(!empty($segment)) $parameters['segment'] = $segment;
+		
 		$url = Piwik_Url::getQueryStringFromParameters($parameters);
         $request = new Piwik_API_Request($url);
         try {
diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php
index c16462b76fde6478b0ffa1f1dcd74ae4d1095e06..2504f61450413be47ac38ba208179588533092b9 100644
--- a/plugins/CustomVariables/CustomVariables.php
+++ b/plugins/CustomVariables/CustomVariables.php
@@ -124,6 +124,8 @@ class Piwik_CustomVariables extends Piwik_Plugin
 	 */
 	public function archiveDay( $notification )
 	{
+		$this->interestByCustomVariables = $this->interestByCustomVariablesAndValue = array();
+		
 		/**
 		 * @var Piwik_ArchiveProcessing_Day 
 		 */
@@ -163,16 +165,17 @@ class Piwik_CustomVariables extends Piwik_Plugin
         	// Custom Vars names and values metrics for Goals
         	$query = $archiveProcessing->queryConversionsByDimension($dimensions, $where);
 
-        	if($query === false) continue;
-		
-    		while($row = $query->fetch() )
-    		{
-				if(!isset($this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) $this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow();
-				if(!isset($this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow();
-				
-				$archiveProcessing->updateGoalStats( $row, $this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
-				$archiveProcessing->updateGoalStats( $row, $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
-    		}
+        	if($query !== false) 
+        	{
+        		while($row = $query->fetch() )
+        		{
+    				if(!isset($this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) $this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow();
+    				if(!isset($this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow();
+    				
+    				$archiveProcessing->updateGoalStats( $row, $this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
+    				$archiveProcessing->updateGoalStats( $row, $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
+        		}
+        	}
     		$archiveProcessing->enrichConversionsByLabelArrayHasTwoLevels($this->interestByCustomVariablesAndValue);
 	    }
 	}
diff --git a/tests/integration/Integration.php b/tests/integration/Integration.php
index 40b93d14215de56602e49f24e8480fa9da85cd69..4080fb7a847497f7d27dfc149459abf1a2e42f0e 100644
--- a/tests/integration/Integration.php
+++ b/tests/integration/Integration.php
@@ -215,7 +215,7 @@ abstract class Test_Integration extends Test_Database
 	 * @param $language 2 letter language code, defaults to default piwik language
 	 * @return array of API URLs query strings
 	 */ 
-	protected function generateUrlsApi( $parametersToSet, $formats, $periods, $setDateLastN = false, $language = false )
+	protected function generateUrlsApi( $parametersToSet, $formats, $periods, $setDateLastN = false, $language = false, $segment = false )
 	{
 		// Get the URLs to query against the API for all functions starting with get*
 		$skipped = $requestUrls = array();
@@ -318,7 +318,7 @@ abstract class Test_Integration extends Test_Database
 	 * 
 	 * @return void
 	 */
-	function callGetApiCompareOutput($testName, $formats = 'xml', $idSite = false, $dateTime = false, $periods = false, $setDateLastN = false, $language = false)
+	function callGetApiCompareOutput($testName, $formats = 'xml', $idSite = false, $dateTime = false, $periods = false, $setDateLastN = false, $language = false, $segment = false)
 	{
 		$path = $this->getPathToTestDirectory();
 		$pathProcessed = $path . "/processed/";
@@ -337,7 +337,6 @@ abstract class Test_Integration extends Test_Database
 			'date'		=> date('Y-m-d', strtotime($dateTime)),
 			'expanded'  => '1',
 			'piwikUrl'  => 'http://example.org/piwik/',
-
 			// Used in getKeywordsForPageUrl
 			'url'		=> 'http://example.org/store/purchase.htm',
 			
@@ -349,7 +348,10 @@ abstract class Test_Integration extends Test_Database
 			'pageUrl' 		=> 'http://example.org/index.htm?sessionid=this is also ignored by default',
 			'pageName' 		=> ' Checkout / Purchasing... ',
 		);
-		
+		if(!empty($segment))
+		{
+			$parametersToSet['segment'] = $segment;
+		}
 		// Give it enough time for the current API test to finish (call all get* APIs)
 		Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated = 10;
 		
@@ -361,13 +363,13 @@ abstract class Test_Integration extends Test_Database
 		{
 			$periods = array($periods);
 		}
-		$requestUrls = $this->generateUrlsApi($parametersToSet, $formats, $periods, $setDateLastN, $language);
+		$requestUrls = $this->generateUrlsApi($parametersToSet, $formats, $periods, $setDateLastN, $language, $segment);
     	
     	foreach($requestUrls as $apiId => $requestUrl)
     	{
     		$request = new Piwik_API_Request($requestUrl);
-    		
-        	// $TEST_NAME - $API_METHOD
+
+    		// $TEST_NAME - $API_METHOD
     		$filename = $testName . '__' . $apiId;
     		
     		// Cast as string is important. For example when calling 
@@ -398,6 +400,7 @@ abstract class Test_Integration extends Test_Database
     			echo "\n";
     		}
     	}
+    	
     	$this->pass();
 	}
 	
diff --git a/tests/integration/Main.test.php b/tests/integration/Main.test.php
index 84560f4a12c7ebdb4ec932170d47c39602aceb58..72f694aa2e64b164f15c04db3d9b8b787c821a9d 100644
--- a/tests/integration/Main.test.php
+++ b/tests/integration/Main.test.php
@@ -145,7 +145,7 @@ class Test_Piwik_Integration_Main extends Test_Integration
 	 * Same as before, but with cookie support, which incurs some slight changes 
 	 * in the reporting data (more accurate unique visitor count, better referer tracking for goals, etc.)
 	 */
-	function  test_OneVisitorTwoVisits_withCookieSupport() 
+	function test_OneVisitorTwoVisits_withCookieSupport() 
 	{
 		// Tests run in UTC, the Tracker in UTC
     	$dateTime = '2010-03-06 11:22:33';
@@ -306,19 +306,19 @@ class Test_Piwik_Integration_Main extends Test_Integration
          
 	}
 	
-	function test_twoVisitsWithCustomVariables()
-	{
+	private function doTest_twoVisitsWithCustomVariables($dateTime, $width=1111, $height=222)
+	{        
 	    // Tests run in UTC, the Tracker in UTC
-    	$dateTime = '2010-01-03 11:22:33';
     	$idSite = $this->createWebsite($dateTime);
     	$this->setApiToCall(array(	'VisitsSummary.get',
     	                            'CustomVariables.getCustomVariables'
     	));
     	ob_start();
-        $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
-    	// -
+		$idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
+		
         $visitorA = $this->getTracker($idSite, $dateTime, $defaultInit = true);
-
+        $visitorA->setResolution($width, $height);
+        
         // At first, visitor custom var is set to LoggedOut
         $visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime());
     	$visitorA->setUrl('http://example.org/homepage');
@@ -327,7 +327,7 @@ class Test_Piwik_Integration_Main extends Test_Integration
         
         // After login, set to LoggedIn, should overwrite previous value
         $visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
-    	$visitorA->setUrl('http://example.org/profile');
+    	$visitorA->setUrl('http://example.org/user/profile');
     	$visitorA->setVisitorCustomVar($id = 1, $name = 'VisitorType', $value = 'LoggedIn');
         $this->checkResponse($visitorA->doTrackPageView('Profile page'));
         
@@ -339,6 +339,7 @@ class Test_Piwik_Integration_Main extends Test_Integration
         // - 
     	// Second new visitor on Idsite 1: one page view 
         $visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true);
+        $visitorB->setResolution($width, $height);
     	$visitorB->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6');
     	$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
     	$visitorB->setVisitorCustomVar($id = 1, $name = 'VisitorType', $value = 'LoggedOut');
@@ -348,13 +349,81 @@ class Test_Piwik_Integration_Main extends Test_Integration
     	$visitorB->setVisitorCustomVar($id = 6, $name = array('not tracked'), $value = 'not tracked');
     	$visitorB->setUrl('http://example.org/homepage');
     	$this->checkResponse($visitorB->doTrackGoal($idGoal, 1000));
+		return $idSite;
+	}
+	
+	function test_twoVisitsWithCustomVariables()
+	{
+		$dateTime = '2010-01-03 11:22:33';
+        $this->doTest_twoVisitsWithCustomVariables($dateTime);
+        $this->callGetApiCompareOutput(__FUNCTION__, 'xml', 
+        								$idSite = 'all', 
+        								$dateTime, 
+        								$periods = array('day', 'week'), 
+        								$setDateLastN = true);
+	}
 
-    	// Test Referer.get* methods in XML
-    	$periods = array('day', 'week');
-    	// Request data for both websites at once
-    	$idSite = 'all';
-    	// Request data for the last 6 periods
-        $this->callGetApiCompareOutput(__FUNCTION__, 'xml', $idSite = 'all', $dateTime, $periods, $setDateLastN = true);
+	function test_twoVisitsWithCustomVariables_segmentMatchVisitorType()
+	{
+		$dateTime = '2010-01-03 11:22:33';
+        $this->doTest_twoVisitsWithCustomVariables($dateTime);
+        
+        // Segment matching some
+        $segment = 'customVariableName1==VisitorType;customVariableValue1==LoggedIn';
+        $this->setApiToCall(array(	
+    	                            'CustomVariables.getCustomVariables',
+//        							'VisitsSummary.get',
+    	));
+        $this->callGetApiCompareOutput(__FUNCTION__, 'xml', 
+        								$idSite = 'all', 
+        								$dateTime, 
+        								$periods = array('day', 'week'), 
+        								$setDateLastN = true,
+        								$language=false, 
+        								$segment
+        );
+	}
+	function test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData()
+	{
+		$dateTime = '2010-01-03 11:22:33';
+        $width=1111; $height=222; $resolution = $width.'x'.$height;
+        $this->doTest_twoVisitsWithCustomVariables($dateTime, $width, $height);
+        
+        // Segment matching ALL
+        $segment = 'resolution=='.$resolution;
+    	
+        $this->callGetApiCompareOutput(__FUNCTION__, 'xml', 
+        								$idSite = 'all', 
+        								$dateTime, 
+        								$periods = array('day', 'week'), 
+        								$setDateLastN = true,
+        								$language=false, 
+        								$segment
+        );
 	}
 	
+	/* Testing a segment containing all supported fields */
+	function test_twoVisitsWithCustomVariables_segmentMatchNONE()
+	{
+		$dateTime = '2010-01-03 11:22:33';
+        $idSite = $this->doTest_twoVisitsWithCustomVariables($dateTime);
+        
+        // Segment matching NONE
+        $segments = Piwik_API_API::getInstance()->getSegmentsMetadata($idSite);
+        $segmentExpression = array();
+		foreach($segments as $segment) { 
+			$segmentExpression[] = $segment['segment'] .'!=campaign';
+		}
+        $segment = implode(";", $segmentExpression);
+        $this->assertTrue(strlen($segment) > 100);
+//        echo $segment;
+        $this->callGetApiCompareOutput(__FUNCTION__, 'xml', 
+        								$idSite = 'all', 
+        								$dateTime, 
+        								$periods = array('day', 'week'), 
+        								$setDateLastN = true,
+        								$language=false, 
+        								$segment
+        );
+	}
 }
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__CustomVariables.getCustomVariables_day.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__CustomVariables.getCustomVariables_day.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c4c1dd5c12bc66a55cb35770151f73ce180693f8
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__CustomVariables.getCustomVariables_day.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2010-01-03">
+			<row>
+				<label>VisitorType</label>
+				<nb_uniq_visitors>2</nb_uniq_visitors>
+				<nb_visits>2</nb_visits>
+				<nb_actions>4</nb_actions>
+				<max_actions>3</max_actions>
+				<sum_visit_length>720</sum_visit_length>
+				<bounce_count>1</bounce_count>
+				<nb_visits_converted>2</nb_visits_converted>
+				<subtable>
+					<row>
+						<label>LoggedOut</label>
+						<nb_uniq_visitors>1</nb_uniq_visitors>
+						<nb_visits>1</nb_visits>
+						<nb_actions>1</nb_actions>
+						<max_actions>1</max_actions>
+						<sum_visit_length>0</sum_visit_length>
+						<bounce_count>1</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+					</row>
+					<row>
+						<label>LoggedIn</label>
+						<nb_uniq_visitors>1</nb_uniq_visitors>
+						<nb_visits>1</nb_visits>
+						<nb_actions>3</nb_actions>
+						<max_actions>3</max_actions>
+						<sum_visit_length>720</sum_visit_length>
+						<bounce_count>0</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+					</row>
+				</subtable>
+			</row>
+			<row>
+				<label>Othercustom value which should be truncated abcdef</label>
+				<nb_uniq_visitors>1</nb_uniq_visitors>
+				<nb_visits>1</nb_visits>
+				<nb_actions>1</nb_actions>
+				<max_actions>1</max_actions>
+				<sum_visit_length>0</sum_visit_length>
+				<bounce_count>1</bounce_count>
+				<nb_visits_converted>1</nb_visits_converted>
+				<subtable>
+					<row>
+						<label>abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx</label>
+						<nb_uniq_visitors>1</nb_uniq_visitors>
+						<nb_visits>1</nb_visits>
+						<nb_actions>1</nb_actions>
+						<max_actions>1</max_actions>
+						<sum_visit_length>0</sum_visit_length>
+						<bounce_count>1</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+					</row>
+				</subtable>
+			</row>
+		</result>
+		<result date="2010-01-04" />
+		<result date="2010-01-05" />
+		<result date="2010-01-06" />
+		<result date="2010-01-07" />
+		<result date="2010-01-08" />
+		<result date="2010-01-09" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__CustomVariables.getCustomVariables_week.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__CustomVariables.getCustomVariables_week.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d3dce53f7720a42c25b41f7521853bd4b65c694c
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__CustomVariables.getCustomVariables_week.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2009-12-28 to 2010-01-03">
+			<row>
+				<label>VisitorType</label>
+				<nb_visits>2</nb_visits>
+				<nb_actions>4</nb_actions>
+				<max_actions>3</max_actions>
+				<sum_visit_length>720</sum_visit_length>
+				<bounce_count>1</bounce_count>
+				<nb_visits_converted>2</nb_visits_converted>
+				<sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
+				<subtable>
+					<row>
+						<label>LoggedOut</label>
+						<nb_visits>1</nb_visits>
+						<nb_actions>1</nb_actions>
+						<max_actions>1</max_actions>
+						<sum_visit_length>0</sum_visit_length>
+						<bounce_count>1</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+						<sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+					</row>
+					<row>
+						<label>LoggedIn</label>
+						<nb_visits>1</nb_visits>
+						<nb_actions>3</nb_actions>
+						<max_actions>3</max_actions>
+						<sum_visit_length>720</sum_visit_length>
+						<bounce_count>0</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+						<sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+					</row>
+				</subtable>
+			</row>
+			<row>
+				<label>Othercustom value which should be truncated abcdef</label>
+				<nb_visits>1</nb_visits>
+				<nb_actions>1</nb_actions>
+				<max_actions>1</max_actions>
+				<sum_visit_length>0</sum_visit_length>
+				<bounce_count>1</bounce_count>
+				<nb_visits_converted>1</nb_visits_converted>
+				<sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+				<subtable>
+					<row>
+						<label>abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx</label>
+						<nb_visits>1</nb_visits>
+						<nb_actions>1</nb_actions>
+						<max_actions>1</max_actions>
+						<sum_visit_length>0</sum_visit_length>
+						<bounce_count>1</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+						<sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+					</row>
+				</subtable>
+			</row>
+		</result>
+		<result date="2010-01-04 to 2010-01-10" />
+		<result date="2010-01-11 to 2010-01-17" />
+		<result date="2010-01-18 to 2010-01-24" />
+		<result date="2010-01-25 to 2010-01-31" />
+		<result date="2010-02-01 to 2010-02-07" />
+		<result date="2010-02-08 to 2010-02-14" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__VisitsSummary.get_day.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__VisitsSummary.get_day.xml
new file mode 100644
index 0000000000000000000000000000000000000000..31a91435930fc8d04b551fc9bcb68ee3bbb8ec27
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__VisitsSummary.get_day.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2010-01-03">
+			<bounce_count>1</bounce_count>
+			<max_actions>3</max_actions>
+			<nb_actions>4</nb_actions>
+			<nb_uniq_visitors>2</nb_uniq_visitors>
+			<nb_visits>2</nb_visits>
+			<nb_visits_converted>2</nb_visits_converted>
+			<sum_visit_length>720</sum_visit_length>
+			<bounce_rate>50%</bounce_rate>
+			<nb_actions_per_visit>2</nb_actions_per_visit>
+			<avg_time_on_site>360</avg_time_on_site>
+		</result>
+		<result date="2010-01-04" />
+		<result date="2010-01-05" />
+		<result date="2010-01-06" />
+		<result date="2010-01-07" />
+		<result date="2010-01-08" />
+		<result date="2010-01-09" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__VisitsSummary.get_week.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__VisitsSummary.get_week.xml
new file mode 100644
index 0000000000000000000000000000000000000000..8619a5f02d1a30076823a2b6f61f7e3fd76dc542
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchALL_noGoalData__VisitsSummary.get_week.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2009-12-28 to 2010-01-03">
+			<bounce_count>1</bounce_count>
+			<max_actions>3</max_actions>
+			<nb_actions>4</nb_actions>
+			<nb_uniq_visitors>2</nb_uniq_visitors>
+			<nb_visits>2</nb_visits>
+			<nb_visits_converted>2</nb_visits_converted>
+			<sum_visit_length>720</sum_visit_length>
+			<bounce_rate>50%</bounce_rate>
+			<nb_actions_per_visit>2</nb_actions_per_visit>
+			<avg_time_on_site>360</avg_time_on_site>
+		</result>
+		<result date="2010-01-04 to 2010-01-10" />
+		<result date="2010-01-11 to 2010-01-17" />
+		<result date="2010-01-18 to 2010-01-24" />
+		<result date="2010-01-25 to 2010-01-31" />
+		<result date="2010-02-01 to 2010-02-07" />
+		<result date="2010-02-08 to 2010-02-14" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__CustomVariables.getCustomVariables_day.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__CustomVariables.getCustomVariables_day.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b9dfec843fd7f5598fb74d1524f01ec7812a0da7
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__CustomVariables.getCustomVariables_day.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2010-01-03" />
+		<result date="2010-01-04" />
+		<result date="2010-01-05" />
+		<result date="2010-01-06" />
+		<result date="2010-01-07" />
+		<result date="2010-01-08" />
+		<result date="2010-01-09" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__CustomVariables.getCustomVariables_week.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__CustomVariables.getCustomVariables_week.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4db157d48bdef99b1d5c923aede8c17c517be94f
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__CustomVariables.getCustomVariables_week.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2009-12-28 to 2010-01-03" />
+		<result date="2010-01-04 to 2010-01-10" />
+		<result date="2010-01-11 to 2010-01-17" />
+		<result date="2010-01-18 to 2010-01-24" />
+		<result date="2010-01-25 to 2010-01-31" />
+		<result date="2010-02-01 to 2010-02-07" />
+		<result date="2010-02-08 to 2010-02-14" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__VisitsSummary.get_day.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__VisitsSummary.get_day.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b9dfec843fd7f5598fb74d1524f01ec7812a0da7
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__VisitsSummary.get_day.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2010-01-03" />
+		<result date="2010-01-04" />
+		<result date="2010-01-05" />
+		<result date="2010-01-06" />
+		<result date="2010-01-07" />
+		<result date="2010-01-08" />
+		<result date="2010-01-09" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__VisitsSummary.get_week.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__VisitsSummary.get_week.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4db157d48bdef99b1d5c923aede8c17c517be94f
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchNONE__VisitsSummary.get_week.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2009-12-28 to 2010-01-03" />
+		<result date="2010-01-04 to 2010-01-10" />
+		<result date="2010-01-11 to 2010-01-17" />
+		<result date="2010-01-18 to 2010-01-24" />
+		<result date="2010-01-25 to 2010-01-31" />
+		<result date="2010-02-01 to 2010-02-07" />
+		<result date="2010-02-08 to 2010-02-14" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchVisitorType__CustomVariables.getCustomVariables_day.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchVisitorType__CustomVariables.getCustomVariables_day.xml
new file mode 100644
index 0000000000000000000000000000000000000000..9717d32e791c1928c4f882c41ca6309237e2cc16
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchVisitorType__CustomVariables.getCustomVariables_day.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2010-01-03">
+			<row>
+				<label>VisitorType</label>
+				<nb_uniq_visitors>1</nb_uniq_visitors>
+				<nb_visits>1</nb_visits>
+				<nb_actions>3</nb_actions>
+				<max_actions>3</max_actions>
+				<sum_visit_length>720</sum_visit_length>
+				<bounce_count>0</bounce_count>
+				<nb_visits_converted>1</nb_visits_converted>
+				<goals>
+					<row idgoal='1'>
+						<nb_conversions>1</nb_conversions>
+						<revenue>0</revenue>
+					</row>
+				</goals>
+				<subtable>
+					<row>
+						<label>LoggedIn</label>
+						<nb_uniq_visitors>1</nb_uniq_visitors>
+						<nb_visits>1</nb_visits>
+						<nb_actions>3</nb_actions>
+						<max_actions>3</max_actions>
+						<sum_visit_length>720</sum_visit_length>
+						<bounce_count>0</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+						<goals>
+							<row idgoal='1'>
+								<nb_conversions>1</nb_conversions>
+								<revenue>0</revenue>
+							</row>
+						</goals>
+						<nb_conversions>1</nb_conversions>
+						<revenue>0</revenue>
+					</row>
+				</subtable>
+			</row>
+		</result>
+		<result date="2010-01-04" />
+		<result date="2010-01-05" />
+		<result date="2010-01-06" />
+		<result date="2010-01-07" />
+		<result date="2010-01-08" />
+		<result date="2010-01-09" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchVisitorType__CustomVariables.getCustomVariables_week.xml b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchVisitorType__CustomVariables.getCustomVariables_week.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3ae3de985315591a7caf55a43fcce0f843360f8c
--- /dev/null
+++ b/tests/integration/expected/test_twoVisitsWithCustomVariables_segmentMatchVisitorType__CustomVariables.getCustomVariables_week.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+	<result idSite="1">
+		<result date="2009-12-28 to 2010-01-03">
+			<row>
+				<label>VisitorType</label>
+				<nb_visits>1</nb_visits>
+				<nb_actions>3</nb_actions>
+				<max_actions>3</max_actions>
+				<sum_visit_length>720</sum_visit_length>
+				<bounce_count>0</bounce_count>
+				<nb_visits_converted>1</nb_visits_converted>
+				<goals>
+					<row idgoal='1'>
+						<nb_conversions>1</nb_conversions>
+						<revenue>0</revenue>
+					</row>
+				</goals>
+				<sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+				<subtable>
+					<row>
+						<label>LoggedIn</label>
+						<nb_visits>1</nb_visits>
+						<nb_actions>3</nb_actions>
+						<max_actions>3</max_actions>
+						<sum_visit_length>720</sum_visit_length>
+						<bounce_count>0</bounce_count>
+						<nb_visits_converted>1</nb_visits_converted>
+						<goals>
+							<row idgoal='1'>
+								<nb_conversions>1</nb_conversions>
+								<revenue>0</revenue>
+							</row>
+						</goals>
+						<nb_conversions>1</nb_conversions>
+						<revenue>0</revenue>
+						<sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+					</row>
+				</subtable>
+			</row>
+		</result>
+		<result date="2010-01-04 to 2010-01-10" />
+		<result date="2010-01-11 to 2010-01-17" />
+		<result date="2010-01-18 to 2010-01-24" />
+		<result date="2010-01-25 to 2010-01-31" />
+		<result date="2010-02-01 to 2010-02-07" />
+		<result date="2010-02-08 to 2010-02-14" />
+	</result>
+</results>
\ No newline at end of file
diff --git a/tests/javascript/Thumbs.db b/tests/javascript/Thumbs.db
new file mode 100644
index 0000000000000000000000000000000000000000..2fdc033a1cd005e370291fb710419b0e7141ca8e
Binary files /dev/null and b/tests/javascript/Thumbs.db differ