Mobile app version of vmapp.org
Login or Join
Shelley277

: Track 301 redirect traffic from domainA to domainB in Google analytics Ive got domainA which has a 301 redirect setup to redirect traffic from domainA to domainB, Id like to track how much

@Shelley277

Posted in: #301Redirect #GoogleAnalytics #Referrer #Tracking

Ive got domainA which has a 301 redirect setup to redirect traffic from domainA to domainB, Id like to track how much traffic is coming through as a redirect from domainA.

How could i track this in Google Analytics ?

Further info my 301 is set in the .htaccess file

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Shelley277

3 Comments

Sorted by latest first Latest Oldest Best

 

@Annie201

Use a server-side scripting language. Create this PHP script:

<?php
$handle=fopen("301tracking.log","a+");
fwrite($handle,"1 guest from IP".$_SERVER['REMOTE_ADDR']."arrived at ".time()."n");
fclose($handle);
$newhost="http://domainB.com";
$url=$newhost.$_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently",true);
header("Location: ".$url,true);
?>
<html>
<head>
<title>Redirect</title>
</head>
<body>
<p>Document moved <a href="<?php echo $url; ?>">here</a></p>
</body>
</html>


Save this as index.php and upload it to document root of domainA. Also, use mod_rewrite to redirect all requests on domainA to the script like so:

RewriteEngine On
RewriteRule ^(.*)$ /index.php [L]


You may have to add a check for the redirect status environment variable right after "RewriteEngine On" just incase the above lines go in an endless loop and/or you get error 500 (internal server error). An alternative is to upload the script to all folders on domainA. To customize the log, change the fwrite line. I apologize for poor grammar in the text part of the code, but you'll understand how the code works when you try it.

10% popularity Vote Up Vote Down


 

@Ann8826881

You wont actually be able to log this with Google analytics. This would require that the page is loaded before it is redirected.

You could try using meta refresh tags on these pages and place your tracking code before the refresh tag.

Alternately, parse your server logs with something like AWstats www.awstats.org/
Your .htaccess is instructing the server to do the redirect before anything else so it will be the only service logging this. (if it is a default configuration)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme