Tracking based on URL referral?

Tracking based on URL referral? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Tracking based on URL referral? error on your web browser. Problem :


Users on my site are given unique URL's for me to then track how many people they have referred to my site.



IE: http://www.example.com/FQ3DL (FQ3DL being the unique code/url)



The first thing I'd like to do is when a user goes to that link, it displays the homepage http://www.example.com/ rather than a 404 error



The second thing is, how would I track how many people have visited that URL? Only through Google Analytics or is there another way to manage it?



Thanks!


Solution :

I would probably write the code myself to track them. Although perhaps it would be easier trying to hook it into analytics. I'm not sure how to do that.



To do the re-direct you would want to use .htaccess (providing you're using Apache server)
The .htacess file might look something like this:



Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([A-Z0-9]5)$ track.php?id=$1 [L]


The RewriteRule there will match someone going to example.com/HJK7D Basically example.com/ and any combination of 5 capital letters and or numbers. This will get re-written and the server will actually pull up track.php?id=HJK7D (in this case)



So drop that .htaccess into the main root directory of your website. Then create a file called track.php which might look something like this:



<?php
if(isset($_GET['id'] && strlen($_GET['id'])==5)
setcookie("id", $_GET['id'], time()+1209600); // expires in 2 weeks


header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/");
?>


Then use the cookie $_COOKIE['id'] to track your visitor through your site.


We hope that this article has helped you resolve the google-analytics, redirects, url error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=