: 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
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
More posts by @Shelley277
3 Comments
Sorted by latest first Latest Oldest Best
Solution that matches your query exactly :
www.lanevance.com/web/web-development/tracking-301-redirects-with-google-analytics
You can set up a campaign
Sample :
domaina.com -> www.domainb.com/?utm_source=domainaredirect&utm_medium=&utm_campaign=301_Redirects
Now you can track this traffic in referrals.
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.
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)
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.