Web Analytics Made Easy -
StatCounter Pulling apart page referrer - CodingForum

Announcement

Collapse
No announcement yet.

Pulling apart page referrer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pulling apart page referrer

    odd one this and I'm trying to get my head around it. I've done some searching around and haven't been able to find any examples.

    user comes from x page via search, shop etc

    I'm capturing the referrer i.e. http://www.google.co.uk/search?hl=en&q=big+jugs

    what I would like to do it take the above and break it down, so I can only take and alert the domain plus query string used.

    domain = google.co.uk
    query(q) = big jugs

    probable straight forward..

    D

  • #2
    A gift for you mate:

    PHP Code:
    <script language="JavaScript">
    <!--
    var 
    url '';
    if (
    document.referrer&&document.referrer!="") {
       
    url document.referrer;
    }
    function 
    getDomain() {
       if (
    url=='') return('');
       var 
    re = new RegExp('^.*://(.*)/.*$');
       var 
    re.exec(url);
       return 
    m[1]?m[1]:'';
    }
    function 
    getQuery(q) {
       if (
    url=='') return('');
       var 
    re = new RegExp('^.*://.*/.*[&?]'+q+'=([^&]*).*$');
       var 
    re.exec(url);
       return 
    m[1]?m[1]:'';
    }

    var 
    domain getDomain();
    var 
    query getQuery('q');
    //-->
    </script
    For testing purpose, you can initially set url to http://www.google.co.uk/search?hl=en&q=big+jugs&sdfds or anything.

    Cheers,
    so happy, so cool

    http://coolersport.info

    Comment


    • #3
      Of course you should also take into account that at least some of your visitors will have that field turned off so that you can't see where they came from.
      Stephen
      Learn Modern JavaScript - http://javascriptexample.net/
      Helping others to solve their computer problem at http://www.felgall.com/

      Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

      Comment

      Working...
      X