Copy link to clipboard
Copied
Trying to use the code below:
<cfset session.path = 'session.path' & '.$HTTP_REFERER.' & '\n'>
to keep a running tally of the pages a person visits while on our site and then using it to output to a variable that can be emailed in a form. How do I get the above code to work?
Copy link to clipboard
Copied
You could use something like this:
<cfscript>
if(!StructKeyExists(SESSION, "pathInfo")){
SESSION.requestID = 0;
SESSION.pathInfo = [];
} else {
SESSION.requestID = SESSION.requestID + 1;
}
pathData = {};
pathData.requestNumber = SESSION.requestID;
pathData.protocol = CGI.server_protocol;
pathData.referer = CGI.http_referer;
pathData.queryString = CGI.query_string;
arrayAppend(SESSION.pathInfo, pathData);
</cfscript>
<cfdump var=#SESSION.pathInfo# />
This, or something like it, (hopefully better) could be contained in a cfc and initialized on session start and updated on each request.
However, the CGI.http_referer is not always going to have a value. Different things can cause it to be blank. For example if a person reaches that page by typing in the URL directly or if they open it through a bookmark it is not going to be available to the browser.
Therefor a better way to get the type of report that you are looking for is to use JavaScript Pixel tags and a utility such as Webtrends or Google Analytics to acquire this information.
Or another way would be to create a parser to parse your Apache or IIS log files. If you are using a JSESSIONID you can use that as the unique value to group your log data into sessions after it has been parsed out and the data you want extracted into query objects. You CANNOT get nearly as much information as you would be able to by using something like Webtrends SDC server and associated JavaScript Tags so it depends greatly on how much detail you require and if your application users will likely always have JavaScript turned on.
Of course that will not be in real time but that does not sound like what you are looking for. A third option is to trap the data and write it to an XML File or Database as it comes in and then supply something like a Flex UI to view it or have a CFReport that uses it as it's datasource.
The real question is why you would want it. This type of data without supporting metrics is pretty much useless as far as Analysis (Analytics) are concerned. I highly suggest you considering using an Analytics Engine to perform this task rather then using CF to do it.
- Joe
Copy link to clipboard
Copied
I concur with the assessment. The right way to obtain this information is by ex post facto statistical analysis of the server logs. No matter what flavor of web-server you use, there's plenty of available software to parse its logfile format. There are also plenty of analysis tools which will give you the answers that you want.
The advantage of these tools is that they are not overwhelmed by data volume. In classic COBOL fashion, they extract the data, sort it, and then run through the result to produce their results ... and for a huge frequently-visited web site "it just takes a little bit longer." (But not nearly as much "longer" as you might suppose.)
Copy link to clipboard
Copied
You can also use the onrequest or onrequesstart method in your applicatiuon.cfc
<cffunction name="onRequestStart" output="true" access="public" >
<cfargument name="requestname" required=true/>
<!-- log #requestname# -->
</cffunction>
-sean
Copy link to clipboard
Copied
<cfset session.path = 'session.path' & '.$HTTP_REFERER.' & '\n'>
I suspect you mean
<cfset session.path = session.path & cgi.HTTP_REFERER>