Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing / writing URL parameter

Status
Not open for further replies.

TheMojo

IS-IT--Management
May 22, 2002
6
US
I am trying to figure out how to handle better tracking of my site visitors and have decided to do the following: in each link that I publish (either in emails or banner ads), I will add a ?[parameter] to the URL link so that I can track the source of the visit.

Now, where I need some help is what kind of scripting can I use in my index.htm file to handle parsing and recording this information into a flat file on the server. I want this flat file to be appeneded to every time someone comes to the website (so the script will append write to the file). Any suggestions or, better yet, sample source code that I can use for this???

Just to be clear, my idea is something like this:

link out on net:
As soon as someone comes to my site with this link, the script would retrieve the source parameter, add a date/time stamp, and add that (optinmsg1, 05/23/2002 11:00 am[cr]) to a flat file on the server called "visitors.txt"

From my research thus far, it seems to me that the final solution is a combination of scripting (in the index.htm file to initially collect the parameter and to also call the CGI program with these parameters) that would then call a CGI script to actually append the info to the flat file. Any and all suggestions would be greatly appreciated...

Oh, and now to reveal what a complete rookie I am... My ISP has provided me with a /cgi-bin directory under my home directory - I am assuming this is where I would place my eventual CGI file... the questions is this: are Perl CGI files just regular text files with a .cgi extension or are they compiled somewhere?
 
In answer to your explicit question, perl is an interpreted language, so a perl file is just text.

The method you will use to invoke the interpreter will depend on how the OS, web server, and perl were installed and configured. You ISP is the only one who can help you.

As far as the referrer-tracking goes, your way is one possibility. However, you may have to publish the link as source-tracker.cgi would the process the input parameter then redirect the browser to your index page.

Another possibility would be to gather the information through log processing. If your ISP has configured their web server to log referrers, then you could process the log for your site to get the same information.
 
Good idea and I will definitely do that for testing purposes. That said, I would like to eventually be able to use the method I initially described if only because the link appears much more friendly that way (so sooner or later I will need to figure out how to parse the parameter with a script in the index.htm file that could then pass that parameter on to the cgi program for processing)... Any sample code that you could point me to? Also, based on your answer about Perl, I could use any text editor to write the script and simply save it with the CGI extension?

Thanks Sleipnir for you help =)) By the way, my Mojo nickname came from Mjollnir... know all the Nordic lore characters - Draupnir is your friend...
 
If you use referrer logging, the URL you must publish is the friendiest of all: " And this is the way apps like WebTrends and SurfStats figure out what search engines sent the most users to your system.

If you use your input-parameter method, you will likely have to publish a URL like " If you don't want to do that, you will have to sweet-talk your ISP into allowing you to execute scripts in your home directory (not just in ./cgi-bin), and have them point your default document to a cgi, not to an HTML file. Remember, HTML is not executable.

Perl is interpreted, so the executable file for a perl script is text. You can use any decent text editor to create them. If you develop on a Win32 machine, remember some of Microsoft's text-editors tend to do things to filenames and file formats you don't want.

As far as the file extension goes, CGI isn't like Win32 -- the file does not necessarily have to be named "foo.cgi" to be executable. Depending on your ISP's server software and configuration, you may be allowed to use "foo.pl" or just "foo". The sysops at your ISP can give you the straight dope.

I don't know of any script samples to do what you want to do. Whenever I have to do something similar, I just turn on referrer logging and let SurfStats go the dirty work for me. If necessary, I will write a quick and dirty perl script to do something SurfStats will not.
 
Keep it coming Sleip :))

To give you a little more background on what I am trying to do...

I really don't care about where the visitors came from (which is readily available from the log files) - what I am really trying to track is what message made them visit the site. So, with opt-in emails for example, the reason I want to specify a parameter is that this parameter will be unique to the message in the opt-in email (so that we can figure out which messages are good vs. those that aren't). Likewise, a banner ad will have a unique message (and will vary over time) - thus what we want to track are the successes of the messages, not so much where they came from (since we can get that from the log file).

On the technical side... By using a script in the index.htm file that parses the parameter from the URL (on page load), and then calls the cgi with that parameter appeneded, it seems like I can leave the cgi script in the cgi-bin directory and not worry about having execute rights in the home directory? I will make a post on one of the scripting language forums to verify, but this seems feasible.

I hope the above clarifies why I want to keep my parameter passing in the URL link that is found either in the opt-in emails or banner ads... we are tracking impact of the messages, not the physical locations of the visitors.
 
Okay, I understand. A single site which may redirect the user to your site may have any one of a number of banners, and you want to know which banner/text actually enticed the user to your site.

Your ISP may or may not allow you to execute scripts outside of your cgi-bin directory. But if they do not, you can always set the URL to point to your script in the cgi-bin directory, rather than index.html in your main directory. The script can then process the source value and redirect the browser to your real index.html.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top