Solved

Track hits for specific asset

Posted on 2006-11-06
6
321 Views
Last Modified: 2013-12-24
Hi, I need to track a specific asset (logo.gif) and report on how many times and from whom this asset is called from the server (server 2003 using IIS v6). What is the log file I need to audit and how does coldfusion monitor that?
0
Comment
Question by:patGRFXS
6 Comments
 
LVL 7

Accepted Solution

by:
aseusainc earned 125 total points
ID: 17884998
You can specify the log file within IIS itself.  Generally, I think it's default in something like C:\windows\system32\logs\w3svc.

Things like webtrends make auditing this a breeze.  Otherwise you could easily write an app in CF to parse out the data.

As far as CF tracking hits, I dont know, never really messed w/ CF logs other than to troubleshoot.
0
 

Expert Comment

by:Klainn
ID: 17887882
Is logo.gif something that people will be clicking on to bring up?

If so you could do something like ..

<a href="hit.cfm"><img src="logo.gif></a>

hit.cfm

<cfquery datasource="#dsn#">
UPDATE LOGO_HIT_COUNTER
SET HIT_COUNT = HIT_COUNT + 1
</cfquery>
<script language="JavaScript" type="text/javascript">
<!--
  window.opener = self;
  window.close();
// -->
</script>


I use this quite a bit. Or if logo.gif isn't something that's clicked on, you could just create hit.cfm and call it on the body of the page holding logo.gif. <body onLoad="http://#CGI.SERVER_NAME#/hit.cfm">
0
 

Author Comment

by:patGRFXS
ID: 17951536
It turns out that the script above from Klainn will not work in this case becouse I am not tracking when the image is being clicked on. I need to monitor the log files and report when a particular image file is called by an outside IP. I know the IP.
0
 
LVL 25

Assisted Solution

by:dgrafx
dgrafx earned 125 total points
ID: 18014158
Hi,
I believe there is a misunderstanding on how to track hits on a specific asset.
forget about tracking logo.gif or parsing log files.
on your page that you want to track you'd put:
<cfset str="ip=#cgi.remote_addr#">
<cfif StructKeyExists(Cookie,"Username")>
<cfset str=ListAppend(str,"Username=#Cookie.Username#","&")>
</cfif>
<cfif StructKeyExists(Session,"WhatEver")>
<cfset str=ListAppend(str,"Whatever=#Session.WhatEver#","&")>
</cfif>
You can put whatever you want to track
the code is simply saying if there is a cookie.username then tack it on
<img src="http://www.yourdomain.com/tracking.cfm?#str#" style="display:none;">
note:
This img tag needs to be within a <cfoutput></cfoutput>
the http of the img tag url will be https if this is a secure server

Then here is an example tracking.cfm
<cfset str=replace(URLDecode(cgi.query_string)," ","","all")>
<cfloop list="#str#" index="ii" delimiters="&">
      <cfset "#trim(listfirst(ii,'='))#"=trim(listlast(ii,'='))>      
</cfloop>
Only you know what you want to track - so I'm just supposing ip
<cfquery datasource="#request.datasource#">
      Insert Into Tracking WITH (tablock)
      (IP,str)
      Values
      ('#trim(IP)#','#trim(str)#')
</cfquery>
be sure you've setup a primary key that is an auto incrementing integer
and if you want a date field set it's default value to (getdate()) instead of inserting date with your query.
I'm inserting 'str' to an ntext field in the table also just for reference

you now have a database record that you can write a report on to view "hits" for a resource

now - with all that said (I realize it may be more than you wanted) you say you know the ip.
does that mean you are looking for just one ip?
write the code into your report to show hits based on this ip
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

895 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

21 Experts available now in Live!

Get 1:1 Help Now