Redirect problem

Hello from I have a bunch of adverts on my website, http://www.spanishpropertymagazine.com/. In order to count the number of click throughs I use the following code.

It works, but I don’t think google analytics picks up the traffic because of the redirect.

How can I get google analytics to pick up the redirect?


<?


$query= "SELECT advert_id, advert_image, advert_shown FROM advert WHERE advert_live = 'yes' $advert_type $advert_order $advert_limit";
//echo "$query<br>";
$result = mysql_query($query);
while ($array = mysql_fetch_assoc($result)) {

	$advert_id = $array['advert_id'];
	$advert_image = $array['advert_image'];
	$advert_shown = $array['advert_shown']+1;

	echo "<a href=\\"http://www.spanishpropertymagazine.com/advert_redirect.php?advert_id=$advert_id\\" target=\\"_blank\\">
	<img src=\\"http://www.spanishpropertymagazine.com/images/adverts/$advert_image\\">
	</a>";


	$update_query="UPDATE advert SET advert_shown = '$advert_shown' WHERE advert_id ='$advert_id'"; 
	mysql_query($update_query);
}


?>

The user is sent to a redirect script.

<?

include "connect.inc.php";

$advert_id = $_GET['advert_id'];

$query = "SELECT advert_link, advert_click_count FROM advert WHERE advert_id = '$advert_id'";
$result = mysql_query($query);

while ($array = mysql_fetch_assoc($result)) {

$advert_link = $array['advert_link'];
$advert_click_count = $array['advert_click_count'] + 1;
mysql_query("UPDATE advert SET advert_click_count = '$advert_click_count' WHERE advert_id = '$advert_id'");

}

$redirect = "Location $advert_link";

//echo "$redirect";
header("Location: $advert_link");
?>

How can I get google analytics to pick up the redirect?

AFAIK, to be tracked by google analytics you need to put some codes (javascript script/code) in the redirect page and you have to have a script that waits at least for a few seconds to stay the page for a while.

But I think this is really related to something Search Engine Optimization related question so better would be better if some moderators move this to corresponding forum. But what I think is ’