Is there a way to pull links from incoming visitors on a page (referrals)? I essentially want to do some if statements.
if user is from Nextag.com {do some javacode} else from Pricegrabber.com {do some javacode}.
Before I can do the if statements I need to find out how that user got on our page (where did they come from). I know google analytics does this but is there a way to hard code it on one page so I can do the above?
You can get the referer URL with
document.referrer, it is supported cross-browser.It might not be set though based on the user’s privacy preferences, firewall, etc. Some proxies also clear or fake it.
You can run some Regexes on the value or use
indexOf, and do some actions based on them.For example (not final code):
MDC Docs on document.referrer