We have a domain that receives some type-in traffic. We want to redirect this traffic to the main domain and also be able to track that traffic as a Campaign in Google Analytics on the main site.
The webserver is IIS8 and it already has an "empty website" bound to this domain to be redirected.
Basically, what is the easiest way to permanently redirect domain to some external domain in ASP.NET without compiling anything and without using any code-behind? How to track that redirected traffic in Google Analytics?
Since you want to track that traffic as a separate GA Campaign, you would first need to prepare a tracking URL with some params that GA uses for campaign tracking. You would then be redirecting to that tracking url. You could either write it manually or use URL builder from Google. You should end up with tracking URL looking similar to this example:
Now we need to redirect to that tracking URL without using code-behind.
The redirect is in fact an HTTP response with HTTP status code either 301 for permanent redirects or 302-307 for temporary and other types of redirects, and new redirect destination url being included as an HTTP header with the name "Location".
Here is how to do a 301 permanent redirect without using any code-behind. We would use VB.NET syntax or you could change it to C#. First, you need to create a
default.aspx file at your root folder in IIS8, then copy-paste the code below into
<%@ Page language="vb" AutoEventWireup="true"%> <script runat="server"> Sub Page_Load Response.Status = "301 Moved Permanently" Response.AddHeader( "Location" ,"http://newdomain.com/new-landing-page?utm_source=old-domain&utm_medium=old-domain-medium&utm_campaign=redirect+from+old+domain+campaign") End Sub </script>
Your redirect should now work, but here is one more quick thing to check:
I am not sure how smart (or not) is google these days to not to double index landing pages where the only difference is google's own campaign tracking parameters, but still... it is better that the redirected page has
<meta canonical ...> tag that lists its original url without any GA tracking parameters, to avoid any duplicate content issues, as explained by Google here. So in our case the landing page should have the following canonical link in its
<head> ... <link rel="canonical" href="http://newdomain.com/new-landing-page" /> </head>
Now finally you are done and you could monitor the newly redirected traffic in Google Analytics Campaigns.
You can add new Headers in the IIS Panel(menu item "Response"):
HTTP/1.1 301 Moved Permanently
But, I didn't test this method :)
Alternatively, instead of WRITING code in
default.aspx file, you could
FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.
Boost your productivity with FavScripts.com!