Solved

document.referrer and click throughs...

Posted on 1998-11-18
14
396 Views
Last Modified: 2012-06-27
gday all :O)
im slowly getting around to having a clickthrough recorder on my site (www.portlandnow.net.au), and this question is to help me set it up.
now i think that to have a working click through meter, i need to do the following... 1: find out where the user came from. 2: send the data to a cgi recording program. 3: access the data in the cgi program at the end of the month to see how many clicks ive had...
the first point is my question. ive been playing around with history.previous, and document.referrer, both of which arent working for me. any suggestions?
p.s. the site is frames based, so would that mean that the previous page is the frameset page, and the true previous page is one before that?
the bottom line question is... how do i display (and then record) the user's previous page?...
thanx in advance
Peter Reefman
0
Comment
Question by:pnreefman
  • 4
  • 3
  • 3
  • +2
14 Comments
 
LVL 4

Expert Comment

by:rafistern
ID: 1274178
1. IE doesn't allow you to access document.referrer . I presume this is a security feature.
2. The referrer should be the page within the frameset, not the frameset.
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1274179
rafistern makes a good point.  This sounds like the perfect case for a web-server log parsing script for perfect accuracy, which is beyond javascript and would require you starting from scratch.  Doesn't sound too appetising.

Have you tried either of these techniques:

1) instead of using document.referrer (which gives you the frameset), use top.document.referrer (since top is the frameset).

2) place the following script in the frameset document:

<script>
<!-- conceal

var Referrer = document.referrer;

// reveal -->
</script>

.and then in your counter script, instead of calling document.referrer, call top.Referrer (which is a variable).


I haven't tested these in multiple browsers, so I didn't submit as an answer.  But I'd be curious to know how it turns out.

Cheers.
-Quixote
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1274180
Q: It should work in all js enabled browsers but IE3

PNReef: It must be loaded from a link. Referrer is not set in IE from direct typing in location or from harddisk.

Michel
0
 

Author Comment

by:pnreefman
ID: 1274181
That works beautifully in IE4.0 Quixote...
I'll try it in a few other (NN3, NN4, IE3) browsers to see how it goes.

0
 
LVL 4

Expert Comment

by:rafistern
ID: 1274182
If you use the HTTP_REFERER environment variable server-side you will not necessarily get what you want. If you have a counter script embedded in an html page then the HTTP_REFERER is the page in which it is embedded. If the page is a cgi script itself then the HTTP_REFERER will be the page from whence you came.
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1274183
rafistern-

Your point is exactly why much of the time this sort of thing is done client-side, using javascript.  By using the document.referrer property of the page, one can dynamicly create an image call like:

<img src="http://www.foo.com/cgi-bin/counter.cgi?referrer=www.bar.com">

And then your counter.cgi can know where the visitor came from (www.bar.com) as well as what page the script is being called from by measuring HTTP_REFERER on the server.  Things can get pretty powerful quickly as soon as you combine client-side work with server-side functionality.

Cheers.
-Quixote
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1274184
Well, I don't know why you need so sophisticated way :)
Isn't it easier to have

<HTML>
<FRAMESET rows="50%,*,1">
 <FRAME NAME="left"   SRC="" >  
 <FRAME NAME="right"  src="kaka.html">  
 <FRAME NAME="hidden" src="/cgi-bin/mylog.pl" FRAMEBORDER="NO" NORESIZE SCROLLING="NO" MARGINHEIGHT=1>
</FRAMESET>
</HTML>

So when someone fall into your frameset
mylog.cgi will be called, this CGI can get
HTTP_REFERRER variable and log it.

In case you want to display user where he came from
you can use in any frame

<script>
 document.writeln(top.document.referrer)
 // oh well, you can call your log cgi here instead
 // of calling from frameset, but this is wired
 // something like this:
 document.writeln('<IMG SRC="/cgi-bin/logit.cgi?ref='+escape(top.document.referrer)+'" BORDER=0 WIDTH=1 HEIGHT=1>');
</script>

Well this script will call CGI for image source,
so your CGI should return image for it, it easy to do
using simple relocation in Perl

print <<EOF;
Location: http://www.yourserver.com/someimage.gif

EOF
# make your log here geting it from QUERRY_STRING


Some differences:
Last solution will makes log each time
user access the document which contains script
In this case inner frame.
(Imagine, user browse several documents at your site
 and turns back to to entry point
)

The way of calling script by loading in third frame (frameset solution) will call log script only once when frameset loaded
I don't know what exactly you want to log,
all document loadings, or only when user comes to your site.
So this is up to you to choose.

Last thing..
Guess you have no rights to run your OWN scripts, and trying to use existing ones like mail.cgi existing scripts.
In this case you can make form in the hidden frame instead
<form ...>
 ...some form fields here...
</form>
than call script
</script>
 //set some field to referrer
 document.forms[0].elements[0].value=""+top.document.referrer;
 document.forms[0].submit();
</script>

In case you put this form in hidden frame, the script
output doesn't matter :)

Limitations:
Calling log as FRAME SRC="/cgi-bin/yourlog.cgi"
Will work in ANY browser which at least support frames;
And don't require JavaScript at all.
(at least for logging)

Using JavaScript is limited to NN3,NN4,MIE4
Sorry, as I remeber MIE3 is nightmare...
I have no MIE3 to check, but I guess it don't support .referrer.

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:rafistern
ID: 1274185
kollegov,
Your frame solution will work fine in IE, but in NS the HTTP_REFERER of the framed page is the frameset.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1274186
rafistern, I just checked your comment, and found that
NN3 and NN4 gives referrer (previous document)
and MIE gives frameset page. Just opposite to your post :)
But you right, MIE as usual deliver more problems :)

So I just make the following solution:

In frameset I have 'hidden' frame
<HTML>
<FRAMESET rows="50%,*,20">
 <FRAME NAME="left"   SRC="" >  
 <FRAME NAME="right"  src="kaka.html">  
 <FRAME NAME="hidden" src="logger.html"
FRAMEBORDER="NO" NORESIZE SCROLLING="NO" MARGINHEIGHT=1>
</FRAMESET>
</HTML>

and this is logger.html
<html>
<script>
function logit()
{document.location="/cgi-bin/vmax/test.cgi?ref="+escape(top.document.referrer+"");
}
</script>

<body>
</body>

<script language="JavaScript1.1">
logit();
</script>
</html>

This pair was tested with NN3, MIE4, NN4
And shouldn't give errors in MIE3
(Sorry have no MIE3 to check:)


0
 
LVL 4

Expert Comment

by:rafistern
ID: 1274187
You're right, I was posting from memory (a bad memory :-)) which my subconcious had obviously subverted..... :-)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1274188
AFAIK IE3 always returns current page as referrer from JavaScript.

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1274189
AFAIK IE3 always returns current page as referrer from JavaScript.

Michel
0
 
LVL 10

Accepted Solution

by:
kollegov earned 100 total points
ID: 1274190
I'm just curious, how it's going, I posted solution which was tested on my server and works fine.
Are you ready to accept it as answer :?)

0
 

Author Comment

by:pnreefman
ID: 1274191
yeah thats fine. :O)
thanx for all that everyone.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now