Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Know where did the come from?  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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: 4096
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Maybe getHeader("referer")?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!