View Full Version : counter - count hte hits for banner
Prath
03-04-2003, 08:43 AM
Is it possible to have counter for banners and store it in text file.
when a user click on a banner. The count for that banner is stored in a text file and redirected to its url, if its url is present in the text file the count gets incremented and if not a new count is started.
And each month a new text file is generated.
do you know the ad rotator ?
more info from the helpfile
------------------------
Ad Rotator Component
The Ad Rotator component creates an Ad Rotator object that automates the rotation of advertisement images on a Web page. Each time a user opens or reloads the Web page, the Ad Rotator component displays a new advertisement based on the information you specify in a Rotator Schedule File.
You can record how many users click each advertisement by setting the URL parameter in the Rotator Schedule file to direct users to the Redirection File. When you specify this parameter, each jump to an advertiser's URL is recorded in the Web server activity logs. For more information on activity logs, see Logging Web Site Activity.
File Names
adrot.dll The Ad Rotator component.
Redirection File An optional file that implements redirection and enables the Ad Rotator component to record how many users click on each advertisement.
Rotator Schedule File A text file that contains the display schedule and file information for advertisements. This file must be available on a Web server virtual path.
Syntax
Set AdRotator = Server.CreateObject("MSWC.AdRotator")
Parameters
AdRotator
Specifies the name of the AdRotator object created by the call to Server.CreateObject.
Registry Entries
None.
Properties
Border Specifies the size of the border around the advertisement.
Clickable Specifies whether the advertisement is a hyperlink.
TargetFrame Specifies the name of the frame in which to display the advertisement.
Methods
GetAdvertisement Gets the specifications for the next scheduled advertisement from the data file and formats it as HTML.
Example
The following example displays a different advertisement each time a user views the Web page.
<% Set ad = Server.CreateObject("MSWC.AdRotator") %>
<%= ad.GetAdvertisement("/ads/adrot.txt") %>
The following HTML is generated by the GetAdvertisement method and added to the page's output, displaying the next advertisement in the Rotator Schedule file.
<A HREF="http://www.msn.com/isapi/adredir.asp?http://www.company.com/">
<IMG SRC="http://msnnt3web/ads/homepage/chlogolg.gif"
ALT="Check out the new Technology Center"
WIDTH=440 HEIGHT=60 BORDER=1></A>
Prath
03-04-2003, 09:40 AM
not using ad rotator.
Its more like count for the link given to a image. without using database
maybe this gives you some inspiration (not quite clear to me what you try to acomplish)
info from helpfile
--------------------------
Counters Component
The Counter component creates a Counters object that can create, store, increment, and retrieve any number of individual counters.
A counter is a persistent value that contains an integer. You can manipulate a counter with the Get, Increment, Set, and Remove methods of the Counters object. Once you create the counter, it persists until you remove it.
Counters do not automatically increment on an event like a page hit. You must manually set or increment counters using the Set and Increment methods.
Counters are not limited in scope. Once you create a counter, any page on your site can retrieve or manipulate its value. For example, if you increment and display a counter named hits in a page called Page1.asp, and you increment hits in another page called Page2.asp, both pages will increment the same counter. If you hit Page1.asp, and increment hits to 34, hitting Page2.asp will increment hits to 35. The next time you hit Page1.asp, hits will increment to 36.
All counters are stored in a single text file, counters.txt, which is located in the same directory as the counters.dll file.
File Names
counters.dll The Counters component.
counters.txt The file that stores all individual counters on a site. counters.txt is a UTF8-encoded file. You can have any Unicode characters in a counter name.
Syntax
Create the Counters object one time on your server by adding the following to the global.asa file:
<OBJECT
RUNAT=Server
SCOPE=Application
ID=Counter
PROGID="MSWC.Counters">
</OBJECT>
Registry Entries
None.
Remarks
Only create one Counters object in your site. This single Counters object can create any number of individual counters.
Note For Personal Web Server on Windows® 95, a Counters component has already been specified in the global.asa file in the default virtual directory. You can work with the Counters object the component creates as if it were a built-in object by calling Counters.Get, Counters.Increment, Counters.Remove, and Counters.Set . You should not create another instance of the Counters object.
Methods
Get Returns the value of the counter.
Increment Increases the counter by 1.
Remove Removes the counter from the counters.txt file.
Set Sets the value of the counter to a specific integer.
Example
Create an instance of the Counters object in the global.asa file with the ID attribute set to Counter:
<OBJECT RUNAT=Server SCOPE=Application ID=Counter PROGID="MSWC.Counters"> </OBJECT>
You can then use that Counters object on one page to create all the counters you need:
There have been <%= Counter.Increment('defaultPageHits') %> to this site.
Then on another page you can increment the counter in the following manner:
You are visitor number<%= Counter.Increment('LinksPageHits') %> to this page.
Note You can obtain this component from the CD included with the IIS Resource Kit.
Prath
03-04-2003, 12:55 PM
Want i wan to do is record the hits for links in a page using filesystem object.
count the hits of url in a asp page and redirect the user to the url after adding the count to that url in text file . and to read the count for all the urls from the text file.
If the url does not exist in the file it has to add it and start the count, otherwise increament the count
Prath
03-04-2003, 01:11 PM
what i want to do is record the hits for links in a page using filesystem object.
count the hits of url in a asp page and redirect the user to the url after adding the count to that url in text file . and to read the count for all the urls from the text file.
If the url does not exist in the file it has to add it and start the count, otherwise increament the count
anyone else ??
i hardly use counters and if i need one, the counters and page counter components have always ben able
to deliver what i need. (can't see what extra's you need but i'm not the smartest one around)
i know how to open, read and write to a textfile (using the FSO) but to search in it, select a number
update it ...
you could always have a sort of counter in an application variable (an array even) and then
put a small function in your global.asa that saves this array to a textfile (say each week
or so, using the datediff functionn etc) (this way, even if your app goes down, you'll only loose the hits from the last week)
Prath
03-04-2003, 02:02 PM
The problem i am facing is that i not able to replace the link and count value for that url after incrementing and besides text file slows the entire process.
Thank you very much for trying to give me a solution.
I will use a database to solve this, as i have time constrains and will try to figure this out when i am free.
Thanks again.
Vladdy
03-04-2003, 06:34 PM
Instead of having a link
<a href="http://www.somesite.com" ....
Make it
<a href="counter.asp?Target=http://www.somesite.com"
In counter.asp
1. Open your file
2. Write target (Request.QueryString("Target")), date, time, whaterver else you are interested in like client IP
3. Close file
4. Redirect to target
If you are interested in a comprehensive DB solution, contact me in a month or two - I'm working on one now.
Morgoth
03-05-2003, 06:01 AM
This is so wierd how this post is taking so long to get answered..
I don't know why that is, but this is what I think he is asking for (minus the idea of making sure the same IP doesn't select the link over and over).
This is a simple IDEA that would work, and I think that is all you really want, correct?
<%
Dim FSO, Counter, File, Clicks, IntID
IntID = Request.QueryString("ID")
If IntID = 1 Or IntID = 2 Then
Set FSO = CreateObject("Scripting.FileSystemObject")
Counter = Server.MapPath("Write_Permission_folder\cc" & IntID & ".txt")
On Error Resume Next
Set File = FSO.OpenTextFile(Counter)
Clicks = CLng(File.ReadLine)
Clicks = Clicks + 1
File.Close
If Error Then
Clicks = 1
End If
Set File = FSO.CreateTextFile(Counter, True)
File.WriteLine(Clicks)
File.Close
End If
If IntID = 1 Then
Response.Redirect("http://link1.com?" & Clicks)
ElseIf IntID = 2 Then
Response.Redirect("http://second.net?" & Clicks)
Else
Response.Redirect("http://NOid.com")
End If
%>
This code works, and works well.
Except, I don't like using On Error, and if you use Brinkster.com, they don't like you uploading this.
Anyone know a different way, other then On Error? I would like to know, and so would Prath if he uses Brinkster.com
Enjoy.
<edit>
My bad, I forgot to tell you how it works.
Well, first you make a link to this file. Example:
<a href="clickcounter.asp?ID=1">Link1.com</a>
Then when they click on that link, it will add 1 to the a text file database. If you don't have a text file in there, because of On Error, it will create one for you. Just make sure the folder it is in has write permissions. Like in /db/ for Brinkster.com.
Now once it adds 1 to your text file it will then, just check the id again, and send you to the site that matches the id number.
This is an easy way to do this (lacking just a single text file to store all information, incuding IPs from users that have already clicked.
Also, when I added to the link ( ?" & Clicks ) to the end of the link so you can see how many times it has been clicked without looking the the text file.. you can remove it..
</edit>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.