Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts

    RewriteRule and Google Analytics - how?

    If I have the site www.mysite.com with the following htaccess:

    PHP Code:
    RewriteRule ^gotocompanysite.php$  http://www.companysite.com/ [R=301,L] 
    and my visitors click on www.mysite.com/gotocompanysite.php they are redirected to companysite.com

    The question is:
    does companysite see in google Analytics that the referrer is mysite.com or does it consider as direct?

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    I believe an address that issues a 301 redirect will not appear in the HTTP_REFERER field. The origin of the request to gotocompanysite.php will.

  • Users who have thanked Cags for this post:

    utnalove (09-30-2011)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    301 redirects should preserve the HTTP_REFERER of the original request, but you can easily test this by going through the redirect and putting this in your address bar:
    Code:
    javascript:alert(document.referrer)
    Or use Firebug/JavaScript Console if your browser supports it.

  • Users who have thanked Inigoesdr for this post:

    utnalove (09-30-2011)

  • #4
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    companysite.com awards me for the visits coming from mysite.com

    I have many fans in Facebook. If I publish the www.mysite.com/gotocompanysite.php link, then they are redirected to companysite.com from my page.

    However it looks like the original referrer is kept: here is what I see after I am redirected to companysite.com:

    This link is shown as referrer:
    Code:
    http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.mysite.com%2Fgotocompanysite.php&h=TAQA_TFfHAQDaBghGWPhNCZ52WVNMYC3uyHLJB7Rj9fT3dA
    What does it mean? Will companysite.com see that the visits came from facebook, or they will see they came from mysite.com?

    What can I do in order to make mysite.com the referrer?
    Thanks
    Last edited by utnalove; 09-30-2011 at 09:47 PM.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by utnalove View Post
    What does it mean? Will companysite.com see that the visits came from facebook, or they will see they came from mysite.com?

    What can I do in order to make mysite.com the referrer?
    Thanks
    Yes, that's what it means.

    You can manually specify the referrer for GA. Just append a value to the destination URL so you know where it came from like: companysite.com?internal=1

    Then on your companysite page you can conditionally add the referrer setting using server-side code like PHP, or even client-side with JS. Here is how you would do it with PHP:
    PHP Code:
    <script type="text/javascript">
    var _gaq = _gaq || [];
    // set your account
    <?php
    if(isset($_GET['internal']) && $_GET['internal'] == 1)
    {
        
    ?>
        _gaq.push(['_setReferrerOverride', 'mysite.com']);
        <?php
    }
    ?>
    _gaq.push(['_trackPageview']);
    // etc..
    </script>

  • Users who have thanked Inigoesdr for this post:

    utnalove (09-30-2011)

  • #6
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    Thanks Inigoesdr, however the companysite.com is not mine and I do not have any influence on that... I cannot change their GA or add JS to their site.

    The only thing I can do is to work on mysite.com... there I can change .htaccess, html, php, etc.

    This action should be invisible to companysite.com - they need to think that all the visits they are receiving are coming from mysite.com - in reallity they:
    --- come from facebook to my site, and then automatically redirected to companysite.com

    I could add the companysite.com directly on facebook, but I want them to see that they are coming from mysite.com

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    How about using the utm* vars in your redirect?
    Code:
    http://companyname.com/?utm_source=mysite.com&utm_medium=cpc

  • #8
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    maybe, I don't know how it works... will companysite.com see it came from facebook still or from mysite.com?

  • #9
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    just tried:

    Code:
    RewriteRule ^gotocompanysite\.php$  http://www.companysite.com/?utm_source=mysite.com&utm_medium=cpc [R=301,L]
    The FireFox RefControl plugin says that the referrer is:
    Code:
    http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.mysite.com%2Fgotocompanysite.php&h=TAQA_TFfHAQDaBghGWPhNCZ52WVNMYC3uyHLJB7Rj9fT3dA

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    It doesn't change the referrer, it just lets GA know where you came from. See the docs for more info.

  • #11
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    382
    Thanks
    150
    Thanked 2 Times in 2 Posts
    Is it enough to put this in the .htaccess in order for companysite.com GA see that it came from mysite.com?

    PHP Code:
    RewriteRule ^gotocompanysite.php$  http://www.companysite.com/?utm_source=mysite.com&utm_medium=cpc [R=301,L] 
    or that Javascript is a must?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •