ColdFusion Tutorial
Tracking users and search engines spiders.
This tutorial will show who is visiting your pages, both users and search engine spiders. You can also see how a visitor goes from page to page on your site. It will also give you information about which page or URL the visitors came from. You will also get the name of the search engines spider and you can see which pages the spider has indexed.
What information we need to capture:
The date and time:
The Now() function returns the current date and time from the server.
If you are using a SQL database, use getDate() instead of Now().
The referring page information:
The CGI variable CGI.HTTP_REFERER will capture referring page information. Using the Cold Fusion LEFT string function strips the extra characters providing the number of characters you choose.
Example: LEFT(CGI.HTTP_REFERER, 128)
Notice:
Some versions of IE 5.5, Opera, and AOL don't even recognize the http_referer command. Netscape 7 doesn't like it at all. Microsoft and Netscape have both realized this problem and aren't offering any resolutions.
The IP address of the client computer:
The CGI variable CGI.REMOTE_ADDR will capture the IP address of the client computer. Example: 216.119.65.128.
The client hostname:
The CGI variable CGI.HTTP_HOST will capture the client hostname server.
The browser type of the visitor:
The CGI variable CGI.HTTP_USER_AGENT will capture the browser type of the visitor.
The page name on your site:
The name of the page is typed in on the pages you want to track.
Example:
For the home page:
<cfmodule template = "admin/act_tracker.cfm" page_track = "Home">
For the product page:
<cfmodule template = "admin/act_tracker.cfm" page_track = "Product">
If you?re using Fusebox, write this code in the fbx_layouts.cfm layout file on the root:
<cfmodule template = "admin/act_tracker.cfm" page_track = "#fusebox.circuit#">
In the examples above we have the tracker.cfm file in the directory admin. Change this if you?re using another path to tracker.cfm.
Creating the database:
Here's an example of an Access database for the user tracking:
|
Field Name |
Data Type |
Description |
| Tracking_ID | AutoNumber | Primary Key. |
| Tracking_Date | Date/Time | The date and time. |
| Tracking_Referrer | Text | The referring page information. |
| Tracking_Client_Address | Text | The IP address of the client computer. |
| Tracking_Client_Host | Text | The client hostname. |
| Tracking_Client_Browser | Text | The browser type of the visitor. |
| Tracking_Resource | Text | The page name on your site. |
Setting global variables in the application file.
The application file:
|
<!--- The name of your database. ---> < cfset request.main_access_DB = "database_name"><!--- The database username. ---> < cfset request.dbusername = "your_username"><!--- The database password. ---> < cfset request.dbpassword = "your_password"> |
The purpose of this file is to get the name of the page(s) you want to track, and save information to the database.
If you have access to the CustomTag directory on your server you can save the file there, or you can save the file in another directory and use cfmodule tag to call the act_tracker.cfm file.
This file needs one parameter, the name of the page you want to track. Below are some examples of the code you need to implement on the pages you want to track.
Here's an example using the cfmodule tag.
<cfmodule template="admin/act_tracker.cfm"
page_track = "Home">
In the example the act_tracker.cfm file is located under the admin directory and the page we want to track is 'Home'.
If you want to track a page called 'Products' in the directory products:
<cfmodule template="admin/act_tracker.cfm"
page_track = "Products">
Or if you track your index.cfm file:
<cfmodule template="admin/act_tracker.cfm"
page_track = "The index file">
If you are using FuseBox, put the code in the fbx_layouts.cfm file:
<cfmodule template="admin/act_tracker.cfm"
page_track = "#fusebox.circuit#">
Notice: The #fusebox.circuit# contains the fuseaction which is being processed.
Here?s code for the act_tracker.cfm file:
<!--- The date and time. ---> < <!--- The referring page information. ---> < <!--- The IP address of the client computer. ---> < <!--- The client hostname. ---> < <!--- The browser type of the visitor. ---> < <!--- The page name on your site. ---> < <!--- Ok we have that data. Insert them into our database. ---> < INSERT INTO tracker_db (Tracking_Date, Tracking_Referrer, Tracking_Client_Address, Tracking_Client_Host, Tracking_Client_Browser, Tracking_Resource) VALUES (#Tracking_Date#, '#left(cgi.http_referer,128)#', '#left(cgi.remote_addr,128)#', '#left(cgi.http_host,128)#', '#left(cgi.http_user_agent,128)#', '#attributes.page_track#') </
If you?re running SQL delete the
<!--- The date and time. --->
<cfset Tracking_Date = Now()>
and replace the insert code:
INSERT INTO tracker_db
(Tracking_Date,
Tracking_Referrer,
Tracking_Client_Address,
Tracking_Client_Host,
Tracking_Client_Browser,
Tracking_Resource)
VALUES (getdate(),
(getdate(),
'#left(cgi.http_referer,128)#',
'#left(cgi.remote_addr,128)#',
'#left(cgi.http_host,128)#',
'#left(cgi.http_user_agent,128)#',
'#attributes.page_track#')
The dsp_tracker.cfm file:
This file will display the contains in the database. You can specify in the query what you want to display.
Here's an example displaying all the fileds and the last 100 records:
|
< cfquery name="User_tracking" datasource="# request.main_access_DB#" username="#request.dbusername#" password="#request.dbpassword #">SELECT * FROM tracker_db order by Tracking_ID Desc </ cfquery>< cfoutput query="User_tracking" maxrows="100">#Tracking_Date# #Tracking_Referrer# #Tracking_Client_Address# #Tracking_Client_Host# #Tracking_Client_Browser# #Tracking_Resource# <br></ cfoutput> |
You can also add an automatic refrech on the dsp_tracker.cfm file, example refrech = 30 sec.
Notice: Rember to make a file that delete data in your database.
Here?s an example of the output of the dsp_tracker.cfm file:
|
ColdFusion Tutorial test
Tracking users and search engines spiders.
No test is available or implemented for this ColdFusion Tutorial.
User Comments: 3
dominios
venta de dominio:
anunctio.com
dominiun.net
imigra.info
Liberanismo.com
vacunate.com
antidopings.com
despistaje.com
viciosydrogas.com
alamanes.com
groupvasco.com
amarsinriesgo.com
enouth.com
sedomania.com
eltrendelasestrellas.com
toursirak.com
importadorajerusalem.com
protesisdeseno.info
protesisdemamas.com
solucioneseconomicas.info
oportunidadeempleo.com
alimentoslight.info
dietalight.info
productoslight.info
corotosusados.com
tuguiadeservicio.com
tumedicoespecialista.com
informate.com.ve
peliculasyvideosgays.com
instructordesexo.com.ar
pornoterapia.com.ar
clubdemujeres.com.ar
infoterapia.com.ar
portalgays.com.ar
sexoterapia.info
pornoterapia.es
bancosocialdelsur.com
libreryamericana.com
tresmens.com
escucho tu oferta...?
Answer to referrer problem with tutorial
First, yes, we have tested this code. And have no problems with it.
Suggestions:
Create a page where you output the contents of cgi.http_referer.
<cfoutput>:#cgi.http_referer#:</cfououtput>
Next, check if the field in your database Allow Zero Lenght for this field.
If you still run into problems, we can set up a page for you.
Regards
Webmaster
referrer problem with tutorial
i've tried adapting only Tracking_Date and Tracking_Referrer portion of your code for our site. it works great if visitors find us by clicking on a link but if they type our domain directly, i get an error saying that "the referer can not be a zero length string".
Have you tested your code for this? my datasource is named "test", the table is "referer" and the two fields are "posted" and "refer". here is how i modified your code. (even if i type a nonsense default value, i get the same zero length string error):
<cfset posted = Now()>
<cfparam name="cgi.http_referer" type="string" default="nothing">
<cfquery name="RefererAndDate" datasource="test">
INSERT INTO referer
(posted,
referer)
VALUES
(#posted#,
'#left(cgi.http_referer,128)#')
</cfquery>
<html>
