How to Get The Data of the Website the Person came from?

We WebFocusToday 13 Mar, 2010
I would like to know how to get the info of the site the person who filled the form was before...

Don't know if this has been asked, but I searched and didn't find an answer.

What I've tried is this:

On the form code, (Form Html) I added this piece of text:

<input type="hidden" value="" id="referrer" />


And on the head of the site, I added:

<SCRIPT LANGUAGE="JavaScript">

function start() {
var ref = document.getElementById('referrer');
ref.value = document.referrer;
}
onload = start; 

</SCRIPT>


Let me know if this can be done and how. Thanks.
Gr GreyHead 13 Mar, 2010
Hi WebFocusToday,

The logic of that looks OK. I've not come across document.referrer before but I think it should do exactly what you want?

What happens when you try it?

Bob
We WebFocusToday 15 Mar, 2010
I just don't get it in the email I get back when a form is filled.
Gr GreyHead 15 Mar, 2010
Hi WebFocusToday,

Ah, make that
<input type="hidden" value="" id="referrer" name="referrer"/>
and maybe add {referrer} to the template?

Bob
We WebFocusToday 16 Mar, 2010
It's a done deal, thanks to the CODE correction you just offered...

It's working perfectly. Thanks!
ja jackie 19 Oct, 2010
Hi - hoping someone can help me - I'm trying to get the website the person came from before they entered our joomla site - the actual referrer, not the joomla page referrer -
and load it into our form. This above post worked but I'm not looking for the last joomla page seen - I'm looking for the site from which they entered the joomla site.

I'm trying to do this w/setting a session variable in the template that the chronoform would then read and pass to the form -
$session =& JFactory::getSession();
$initref=($_SERVER['HTTP_REFERER']);
$session->set( 'initialreferrer', $initref );

but am not having luck with this. I'm putting this code into the Chronoform to retrieve the variable set above:
$session =& JFactory::getSession();
$theexternalreferrer = $session->get( 'initialreferrer', 'empty' );

But I'm not sure when I use the $session =& JFactory::getSession(); that it's not just setting a whole different session...??
What's the best way to get the external referrer when the user first enters Joomla, store it and then pass it in a hidden form field if the user uses the form?
thank you very much - am in the mud on this one
Jackie
Gr GreyHead 23 Oct, 2010
Hi Jackie,

I've finally got the write this up in a How_to document here

This does a bit more than you need: [list]
  • Grabs and stores the Referer URI
  • Grabs and stores the User IP address
  • Tracks the pages the user visits on your site
  • Extracts the search keywords I the Referer URI was from Google, Bing, MSN, Yahoo or Ask
  • Adds the results to an admin email if the user submits a Contact Form (or any other form if you choose).
  • [/list]

    Bob

    PS I'm charging $10 for this document as it's quite a complex app. I'll send you a PM with a coupon to get a free copy as you asked the question.
    ma marcielo 16 Dec, 2010
    Hi

    I tried the code posted above and it worked fine, but I wanted some more user information included to the mail. So I purchased the guide, it should be pretty simple to setup, and its probably just me, but I can't make it work😶 . I have chronoform 3.1 RC5.5. I installed the module mentioned in the guide, enabled it, with a link to a php file with the snippet in the root of my joomla installation.
    I also inserted a code to the before mail textbox in chronoform. There was an error on line 47, so I fixed that, Im not at php coder so I'm not sure if its correct:

    $temp[] = "Keyword $i: "$keyword";

    when it should say (?)

    $temp[] = "<p>Keyword $i: $keyword</p>";

    Nevertheless after submitting the form I get a new error on the last line - the php tag

    I also did insert the tracking tag in the email template.

    Also I'm not sure if I'm out of line posting here😶
    Gr GreyHead 16 Dec, 2010
    Hi marcielo,

    Posting this here is fine. I'll happily fix any bugs. I do have the code working so there shouldn't be anything too serious.

    I don't think that the <p> & </p> tags are going to cause or fix this problem. Please can you post the whole block of code here so that I can see exactly what is happening.

    Bob
    ma marcielo 16 Dec, 2010
    No thats true that aint going to fix it, but I think there was a " missing there

    Here is the code

    <?php
    /**
    * @package ChronoForms
    * @copyright Copyright (C) 2010 Bob Janes. All rights reserved.
    * @license GNU/GPL, see LICENSE.php
    */
    /* ensure that this file is not called directly */
    // uncomment the following line if you include this code from a file
    defined('_JEXEC') or die('Restricted access');
    $gh_session =& JFactory::getSession();
    $gh_ip =& $gh_session->get('gh_ip', '000.000.000.000', 'gh');
    $gh_pages =& $gh_session->get('gh_pages', array(), 'gh');
    $gh_referers =& $gh_session->get('gh_referers', array(), 'gh');
    // add the user IP address
    $message = "";
    $message .= "<div >IP: $gh_ip</div>";
    // add the referer URL
    if ( count($gh_referers) ) {
    $i = 1;
    $temp = $keywords = array();
    foreach ( $gh_referers as $referer ) {
    $temp[] = "<p>Referer $i: $referer</p>";
    $keywords_used = getKeywords($referer);
    if ( $keywords_used ) {
    $keywords[] = $keywords_used;
    }
    $i++;
    }
    $message .= "<div>".implode('br />', $temp)."</div>";
    // add the pages visited
    if ( count($gh_pages) ) {
    $i = 1;
    $temp = array();
    foreach ( $gh_pages as $page ) {
    if ( $page ) {
    $temp[] = "<p>Page visited $i: $page</p>";
    $i++;
    }
    }
    $message .= "<div>".implode('br />', $temp)."</div>";
    }
    // add the search engine keywords
    if ( count($keywords) ) {
    $i = 1;
    $temp = array();
    foreach ( $keywords as $keyword ) {
    $temp[] = "<p>Keyword $i: $keyword</p>";
    $i++;
    }
    $message .= "<div>".implode('br />', $temp)."</div>";
    }
    JRequest::setVar('tracker_message', $message, 'post');
    // function to extract keyword form a search engine URI
    function getKeywords($query)
    {
    if ( strpos($query, "google.") ) {
    $pattern = '%^.*/(?:search|maps).*[?&]q=(.*)%';
    } elseif ( strpos($query, "msn.") || strpos($query, "live") ) {
    $pattern = '/^.*q=(.*)$/';
    } elseif ( strpos($query, "yahoo.") ) {
    $pattern = '/^.*[?&]p=(.*)$/';
    } elseif ( strpos($query, "ask.") ) {
    $pattern = '/^.*[?&]q=(.*)$/';
    } elseif ( strpos($query, "bing.") ) {
    $pattern = '/^.*[?&]q=(.*)$/';
    } else {
    return false;
    }
    preg_match($pattern, $query, $matches);
    if ( strpos($matches[1], '&') ) {
    $querystr = substr($matches[1], 0, strpos($matches[1], '&'));
    } else {
    $querystr = $matches[1];
    }
    return urldecode($querystr);
    }
    ?>
    Gr GreyHead 16 Dec, 2010
    Hi Marcielo,

    My apologies, you are exactly right. There is an extra " and a missing } :-(
        $message .= "<div>".implode('br />', $temp)."</div>";
    } // <-- add this bracket
    
    // add the pages visited

        foreach ( $keywords as $keyword ) {
            $temp[] = "Keyword $i: $keyword"; // <-- remove extra quote from this line
            $i++;
        }

    Bob

    PS I've updated the document to fix this errors - please email me if you'd like a copy.
    ma marcielo 11 Jan, 2011
    Thank you again that worked nicely
    This topic is locked and no more replies can be posted.