• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Know where did the come from?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

What I want to do, is to know where the user came from. For example a user has found my website via Google or Yahoo.
Is there a method to get the URL of these websites?

I use this method request.get("Referer"); but it returns only the latest page the user has requested.

Thank you,

Abu Romaysa
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Azz Romaysa:

I use this method request.get("Referer"); but it returns only the latest page the user has requested.



No, it shows the page they were on when they clicked the link to the current resource. If they found your site on Google and clicked the link to it, Google would show up in the referrer variable (along with the search criteria they used to arrive at that particular google page)

Example:
Here is the referer variable from a hit to my site:



In it we can see that they came from www.google.com.
Also, becuase Google puts the search terms right in the querystring, (requests with the GET method) we can also see the keywords that the user entered to get to that particular Google page. ("servlet" and "init").
 
Azz Romaysa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I'm sorry, it shows the page they were on when they clicked the link to the current resource.

Let's say that the user come from google, and has requested a number of pages in my website. Finaly he has dicided to register. How could I then know that he came from Google?

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each request doesn't carry a full history of where a user has been and there's no way you will always know where a user came from.
Some browsers may not send the referer information.
You won't get a referer if someone types the address in manually or opens a page from their browsers bookmark section (favorite places).

What you could do is put the referer value into session when a user hits your front page.

If your server has access logging turned on, take a look at the logs.
Doing so will give you an idea of how the referer varible works.
You can also see exactly where a every user has been on your site.
Following an IP up to the first occurance will usually get you an informative referer variable.
Access logs are pretty standard and are meant to be parsed by programs (such as Webalizer) so you could write a program that finds this out by interrogating them.
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest a cookie since it is lightweight. Have a one-time created cookie that is created the first time the user accesses any part of the site (assuming their first time they came from an external site such as google).

So each page would do something like "If cookie does not exist create one with last page visited". Since this would be on every page, it would have to contain some external link (although not neccessarily google).

Then if the user registers, save this information iff it matches certains patterns. For example, if it contains www.google.com, its fine to save, but some may contain garbage values or irrevelant link so you just skip those. It should work in 80-90% of the cases the user found you via a search engine. As with most things on the web, nothing is bullet proof.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


request.get("Referer");



I couldn't find this method in ServletRequest class. I appreciate if you can tell me where I can find this method.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe getHeader("referer")?
 
reply
    Bookmark Topic Watch Topic
  • New Topic