How to create a tracking cookie

Jul 30, 2012, by admin

Tracking cookies enable the owner of a Web site to obtain information from visitors to his or her site. The Web site’s owner can use the information to learn more about visitors and/or provide visitors with a more personalized and streamlined experience. For example, a cookie can store a Web site visitor’s user name and password so the visitor does not have to inhabit this information every time he or she visits the Web site, saving the visitor time.

Steps to create a tracking cookie

1.Plan on what information you want your cookie to collect. Before you create a tracking cookie, you should determine what type of information you want to track from visitor’s to your Web site. For example, you may find it significant to know the zip code of a person visiting your Web site if your Web site sells products that need shipping costs and certain sales taxes.

2.Use HTML. If you have created your Web site using HTML code and are somewhat recognizable with programming, you can make a tracking cookie from scratch.

  •    Use the “Response” command to write a cookie on a visitor’s computer. “Response.Cookies(“CookieName”)=value” is the most basic form of this code. The code: “Response.Cookies(“VisitorName”)=Request.Form(“UserName”)” would allow you to keep track of a visitor’s user name.
  •     Use the “Request” command to retrieve the cookie. “Request.Cookies(“CookieName”)” would allow you to retrieve the information from the visitor’s computer when the visitor returned to your Web site.

3.Note however that standard HTML does not have commands. “Response” and “Request” are part of Microsoft’s ASP (active server pages). See http://www.w3schools.com/asp/coll_cookies_response.asp If your web server does not support ASP, you’ll have to investigate other methods of generating cookies, such as CGI scripts or PHP.

4.Think tracking cookie software as an option to writing your own code. There are software programs out there that will do the heavy coding for you.

  •   Software will allow you to make certain kinds of cookies; sometimes a single type of software will only allow you to make a specific cookie. Some of this software is considered “freeware,” and thus won’t cost you anything. Tracking cookie software can help with restricting how many times a visitor can download software from your Web site by remembering that the software was already downloaded.

5.Add security to your cookie. Internet security is a key concern of most Internet users. It’s important to provide security so that visitors’ information is protected.

  •  A domain property will limit the cookie from being read by another Web site. A sample of the code for this is: Response.Cookies(“CookieName”).Domain = “www.mydomain.com”
  •  A path property restricts the cookie to being read by a specific path. A sample of the code for this is: Response.Cookies(“CookieName”).Path = “/maindir/subdir/path”

6.Give your cookie an expiration. A cookie will expire once the Web browser the visitor uses to view your Web site is closed. An expiration date must be set if you want to store the cookie so that when the user comes back the information is saved. An example of this code is: Response.Cookies(“CookieName”).Expires=#January 01, 2010# (assuming a January 01, 2010 expiration date).