How do I configure Apache Web servers for user-tracking Cookies?
Answer
For products: Webtrends Enterprise 7.0 Webtrends Professional 7.0 Webtrends Small Business 7.0 Webtrends Analysis Suite 7.0x Webtrends Log Analyzer Advanced 8.x Webtrends Log Analyzer 8.x Webtrends Intelligence Suite 4.0x Webtrends Reporting Center 6.x
Last modified: 1/1/2011
Introduction: As many webmasters have discovered, there is a certain level of inaccuracy associated with tracking users by IP addresses. Unfortunately, this is not due to a limitation with the web server or with Webtrends software. It is a result of the way many larger ISPs route their customers. Fortunately, however, there is a more accurate way to track individual users: a tracking cookie. Cookies are pieces of information that are stored in the clients browser. Once a visitor has received a cookie from your site, the information in the cookie is stored on the visitors hard drive. If the visitor returns to your site at some point in the future, his or her browser will send the cookie to your web server. This informs your web server that the visitor has been to your site before. Cookies can store a variety of information, however, this article will deal with a special kind of cookie called a tracking cookie. The idea behind a tracking cookie is to accurately track how many users visit your site, and how often. The actual value of a tracking cookie is essentially a string of random numbers - it doesn't matter what data is stored in the cookie, the important part is that each visitor receives a different cookie.
Apache web servers have the ability to issue user tracking cookies through a module called mod_usertrack. In order to utilize these tracking cookies, the Apache installation must have mod_usertrack enabled. Standard Apache installations sometimes come with mod_usertrack either compiled into the Apache httpd binary or built into Apache as a Dynamic Shared Object, also referred to as a DSO. Mod_usertrack must exist in either form for Apache to issue cookies. To check if mod_usertrack is compiled, run httpd -l from your Apache directory. You should get a listing of compiled modules; check to see if it is listed. If not, you can check to see if it loads at runtime as a DSO. Open up the httpd.conf file in the Apache conf directory, and within the Dynamic Shared Object (DSO) Support section, there should be two entries: LoadModule usertrack_module libexec/mod_usertrack.so AddModule mod_usertrack.c If you do not have mod_usertrack in place statically or as a DSO you should consider either recompiling Apache with mod_usertrack support or adding mod_usertrack as a DSO module to your current installation. You can add mod_usertrack as a DSO as long as your existing Apache has mod_so.c (a module that allows you to load other modules at run time) compiled in and supports DSO. Please refer to Apache Documentation http://httpd.apache.org/docs-2.0/ for further information. Once mod_usertrack has been compiled into your Apache server, all you need to do is enable the cookie and then it needs to be configured.
First, plan your server outage. If this web server is not in production, or if it has a low enough priority to be stopped briefly, the simplest thing to do would be to modify your configuration files, and then stop and restart Apache. If this is a high-priority production server, you may want to plan the server restart for sometime early in the morning, to minimize downtime. In any event, a backup of any configuration files to be modified is recommended. Then, find the main Apache configuration file - this is usually called httpd.conf.
Below are the lines that should be added to the Apache configuration file: CookieTracking on CookieName Webtrends CookieExpires "6 months"
These lines should be added in the appropriate place in the httpd.conf file. If this web server hosts only one web site, find the part of the configuration file labeled Main Server Configuration; if more than one site is hosted from the server, these entries may be placed in each virtual host directives section, and they need not be the same for each site.
Naturally, the name of the cookie and the expiration period may be changed, if you wish. If the CookieExpires directive is not used, cookies last only for the current browser session, which could mean Apache may issue a new cookie to returning users, erroneously logging them as unique viewers. Also, keep in mind that a valid cookie name must be specified; results are unpredictable if you use a name containing unusual characters. Valid characters include A-Z, a-z, 0-9, "_", and "-".
Next, find the LogFormat line of your configuration file. Once again, the LogFormat may be defined globally, in the general area of the configuration file, or you may define different LogFormats for each virtual host. LogFormat uses a string of characters, enclosed in double-quotes, to specify what information you would like in your log file, and how it should appear. While Webtrends cannot guarantee the success of particular Apache configuration settings, this is the LogFormat string that has worked well for us:
The entire argument is contained within double-quotes. Within the argument, double-quotes are used, but you will notice that they are always immediately preceded by a backslash / character. This is called the escape character. The escape character means, "don't treat the next character as having a special meaning, just print it." So, a double-quote without an escape character would signify the end of the LogFormat string; but a double-quote with an escape character means, "just print a double-quote in the log file."
Now, let us look at the actual fields. Each percent sign % signifies a field. We will not discuss all of the field designations here; for more information, try this page http://httpd.apache.org/docs/mod/mod_log_config.html?formats in Apaches documentation. One note, however, you will notice that the Cookie directive is followed by the letter i. In some documentation, you may see this listed with a letter n instead. It is very important that you use the i; otherwise, your tracking cookie will not work correctly, and Webtrends will misinterpret your data.
Finally, you will notice the word combined at the end of the LogFormat line, after the final set of double-quotes. In this case, combined is a name that you have provided to describe this particular LogFormat. If you wish, you could define several different LogFormats with different names at the end, and. use them to create more than one log file. The name you specify will be used in your CustomLog directive; for more information on CustomLog, consult Apache's documentation at:
After these changes have been made, all that remains is to start the Apache server and visit the web site. If you check the log file, you should see a new field at the end of each line containing cookie values. Now configure your Webtrends software to validate this cookie to track visitors. To do this, in your Cookie settings, check the option "Use this Cookie", and in the field provided, enter the name of the cookie you designated. Now, when Webtrends analyzes your log files, we will use the unique cookie values assigned to each visitor to track visitor sessions with far more accuracy than is possible without cookies.
Note: Webtrends does not support Apache products, nor is this article intended to be official Apache documentation. If you are unsure of any of the steps described, please consult Apache's Documentation
Before making changes, or any other alterations to your web server, we would strongly advise you to complete a trial run on a test server to verify the correct results.