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.

 

Follow this link to see an animated tutorial how to add and manage your data source connections and Data Source Names (DSNs).

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 act_tracker.cfm file:

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. --->

<cfset Tracking_Date = Now()>

<!--- The referring page information. --->

<cfparam name="cgi.http_referer" type="string"default="">

<!--- The IP address of the client computer. --->

<cfparam name="cgi.remote_addr" type="string"default="">

<!--- The client hostname. --->

<cfparam name="cgi.http_host" type="string"default="">

<!--- The browser type of the visitor. --->

<cfparam name="cgi.http_user_agent" type="string"default="">

<!--- The page name on your site. --->

<cfparam name="attributes.page_track" type="string" default="Page Name">

 

<!--- Ok we have that data. Insert them into our database. --->

<cfquery name="tracker_insert" datasource="your_datasource" username="your_username" password="your_password">

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#')

</cfquery>

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:

 Mar 31 2004 4:16AM 209.30.39.25 Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) home
 Mar 31 2004 4:15AM http://www.google.fi/search?q=smiley+meaning&ie=UTF-8&oe=UTF-8&hl=fi&lr= 195.237.145.34 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0; Q312461) chat
 Mar 31 2004 4:07AM 66.196.72.57 Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) products
 Mar 31 2004 3:50AM 211.133.211.172 Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) home
 Mar 31 2004 3:10AM http://www.scriptsearch.com/cgi-bin/jump.cgi?ID=8938 213.33.152.252 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) home
 Mar 31 2004 3:07AM http://www.uptimebot.com 63.209.27.6 UptimeBot(www.uptimebot.com) home
 Mar 31 2004 3:06AM 81.152.214.226 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) home
 Mar 31 2004 3:05AM http://www.applayit.com/ 193.95.153.4 Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0) coldfusion
 Mar 31 2004 3:05AM http://www.google.ie/search?hl=en&ie=UTF-8&oe=UTF-8&q=coldfusion+tutorial&meta= 193.95.153.4 Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0) home
 Mar 31 2004 2:59AM 61.153.248.195 Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) home
 Mar 31 2004 2:56AM 62.102.29.2 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 chat
 Mar 31 2004 2:33AM 216.39.50.158 Scooter/3.3_SF home
 Mar 31 2004 2:09AM http://www.google.co.uk/search?hl=en&ie=UTF-8&oe=UTF-8&q=animated+lines+in+flash&spell=1 81.134.39.83 Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0) flash_tutorials
 Mar 31 2004 1:44AM 64.68.82.169 Googlebot/2.1 (+http://www.googlebot.com/bot.html) home

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>

Add your comments

Your Name*:
Your Email:
Site URL:
Site Name:
Comemt Title*:
Your Comment*:
Key Phrase*:
X3w
Your IP Address: 38.103.63.62
 

ScandicWeb is own by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.

[Home [Site Map [Privacy Statement [Site Feedback] [About ScandicWeb]


[ColdFusion [Flash [Search Engine Optimization [Graphics [Cascading Style Sheets (CSS) [JavaScript (JS) [Software]

Partner sites: ScandicSoft


Server time: 19. November 2008 Wednesday