• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Tracking users, please help

Contributor ,
Feb 10, 2008 Feb 10, 2008

Copy link to clipboard

Copied

Hello;
I wrote a small tracking system for my web site. I am trying to upfrade it to work in CF 8. Here is what I am doing.

I had this code on the index.cfm page of my site. I am attempting to move it to the Application.cfc file. When I do, it registers in the DB every time the user hits a page or clicks a link. I don't want it to do that. I do want it to tell me when they hit the site, and if I can what page they came in on.

Here is my code:
<cfquery name="tracking" datasource="my-DB" dbtype="ODBC">
INSERT INTO tracking (REMOTE_ADDR, HTTP_USER_AGENT, TRACK_DATE, PageID)
VALUES('#REMOTE_ADDR#', '#HTTP_USER_AGENT#', #CreateOdbcDateTime(now())#)
</cfquery>

My pageID is where I want the information on what page the user came in on to go.
Is this possible to limit the number of hits counted by the Application.cfm, instead of adding info to the DB everytime they click a link?

Here is my application.cfc code so far:

<cfset THIS.name = "my-web">
<cfset this.sessionManagement="yes">
<cfset this.clientManagement=true>

<cffunction name="onApplicationStart" returntype="boolean" output="false">
<cfset APPLICATION.appStarted = now()>
<cfreturn true>
</cffunction>

<cffunction name="onApplicationEnd" returntype="void" output="false">
<cfargument name="appScope" required="True">

<cflog file="#THIS.name#" text="App ended after #dateDiff('n' , ARGUMENTS.appscope.appStarted,now())# minutes.">
</cffunction>

<cffunction name="onRequestStart" returntype="boolean" output="true">
<cfset request.datasource = "my-db">
<cfset sitePath = " http://www.myweb">

<!--- this is where I was placing my tracking code --->
<!--- <cfquery name="tracking" datasource="my-DB" dbtype="ODBC">
INSERT INTO tracking (REMOTE_ADDR, HTTP_USER_AGENT, TRACK_DATE, PageID)
VALUES('#REMOTE_ADDR#', '#HTTP_USER_AGENT#', #CreateOdbcDateTime(now())#)
</cfquery> --->

<!--- Start True Url Variables --->
<cfloop list="#removeChars(cgi.path_info,1,len(cgi.script_name))#" delimiters="/" index="variableSet">
<cfscript>
variableName = "url." & listGetAt(variableSet,1,'.');
expression = listGetAt(variableSet,2,'.');
</cfscript>
<cfparam name="#variableName#" default="#expression#">
</cfloop>
<!--- Finish True Url Variables --->
<cfreturn true>
</cffunction>
</cfcomponent>

Thank you.

Phoenix
TOPICS
Advanced techniques

Views

352

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Feb 10, 2008 Feb 10, 2008
I don't have an osessionstart in this, I have an application start, I put it in there and it doesn't work. What would I write for an on session start?

and what code do I add to write to the Db what page they came in on? (If they come in on about.cfm, or contact.cfm, ect.)

Votes

Translate

Translate
Explorer ,
Feb 10, 2008 Feb 10, 2008

Copy link to clipboard

Copied

Put it in the OnSessionStart functrion of the Application.cfc. That way it will only run at the start of a user's session rather than on every page hit. Each visitor's session starts with the first .cfm page they visit.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 10, 2008 Feb 10, 2008

Copy link to clipboard

Copied

LATEST
I don't have an osessionstart in this, I have an application start, I put it in there and it doesn't work. What would I write for an on session start?

and what code do I add to write to the Db what page they came in on? (If they come in on about.cfm, or contact.cfm, ect.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation