2

I have a olddomain.com that redirects to newdomain.com and we want to know the best way to track how many people are coming from olddomain.com on Google Analytics?

Currently I have two rewrite rules which basically just redirects olddomain.com to newdomain.com like below. What I want to accomplish is to be able to somehow log into Google Analytics and track how many times visitors came from olddomain.com. I have seen this article but its for Apache server using .htaccess. I would like to know how to do this with IIS 7 using rewrite rules or redirects so GA can track these also.

<rule name="Force HTTPS and use production domain - olddomain.com" stopProcessing="false">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^m\.olddomain\.com$" />
        <add input="{HTTP_HOST}" pattern="^olddomain\.com$" />
        <add input="{HTTP_HOST}" pattern="^ww2\.olddomain\.com$" />
  <add input="{HTTP_HOST}" pattern="^www\.olddomain\.com$" />
</conditions>
    <action type="Redirect" url="https://www.newdomain.com{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>



<rule name="Force HTTPS and use production domain - olddomain.com" stopProcessing="false">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^m\.olddomain\.com$" />
        <add input="{HTTP_HOST}" pattern="^olddomain\.com$" />
        <add input="{HTTP_HOST}" pattern="^ww2\.olddomain\.com$" />
  <add input="{HTTP_HOST}" pattern="^www\.olddomain\.com$" />
</conditions>
    <action type="Redirect" url="https://www.newdomain.com{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>

3
  • Somebody on StackOverflow figured out how to append values to the query string when redirecting: How to append query string & value via IIS rewrite rule?. I'm not sure I understand their solution, nor do I have an IIS server to test it with. Oct 18, 2016 at 8:22
  • It looks like you might just be able to append the values using url="https://www.newdomain.com{REQUEST_URI}?utm_campaign=domainnames&utm_medium=domain&utm_source=olddomain.com" Oct 18, 2016 at 8:24
  • Stephon Ostermiller, I tried implementing it but it just gave me a blank white page. I was however able to just run https://www.newdomain.com{REQUEST_URI}?utm_campaign=dom‌​ainnames&utm_medium=‌​domain&utm_source=ol‌​ddomain.com and it logged into Google. I think I need to somehow redirect and then rewrite the URL. Oct 18, 2016 at 21:21

1 Answer 1

1

You could change your redirected URL to have something like

?redirect

appended to the end of it. It would have no effect on the page, but in GA you could filter those URLs out to get a count.

4
  • Whenever I do add the url="the_entire_url" the config says its invalid XML. I tried putting each _utm= parameter into a {QUERYSTRING} and it was valid XML but I still got a blank page on the primary domain name. This is proving to be very difficult for me to pull off. But I thank you for trying. BTW, what did you mean appending ?redirect to the end of the url like this "traveltexas.com/…" Oct 21, 2016 at 18:28
  • The problem is the ampersands (&)in the full URL. To put them into an XML context you need to escape each one with &amp; So utm_campaign=My+Campaign&utm_source=Redirect would become utm_campaign=My+Campaign&amp;utm_source=Redirect within the XML configuration document. Oct 22, 2016 at 9:05
  • I will try what I have below: Oct 24, 2016 at 21:05
  • newdomain.com/…. I will have to try after I resolve some github dns issues I'm having. Oct 24, 2016 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.