Sitewide Implementation of DWStats
Now that you have DWStats, and it is installed on your site, you need to add DWStats to all the pages in that site. But, adding 100+ trackers doesn’t sound like fun. This tutorial will show you how to do this much more efficiently.
First of all, insert a tracker into a page. Switch to code view, and you’ll see something like this:
![]()
Notice the two circled sections of code. This is how DWStats determines the page name to record. By editing these values, you can set what DWStats will record.
To make the tracker available to all files in our site, we need to put the tracker code in an include file, such as a header or footer file. Paste the tracker code into the include file.
Now, instead of using a static value for the page name, we will replace the value with the variable of the current page location (see code). Also, we will set the location of DWStats to be /dwstats instead of a relative path in line 2.
Use the following code in lieu of the lines circled above:
1: var pageName = ‘<?php echo($_SERVER["PHP_SELF"]); ?>’;
2: <img src="/dwstats/send.php?nojs=1&pnm=<?php echo($_SERVER["PHP_SELF"]); ?>" width="0" height="0">
ASP:
1: var pageName = ‘<%=(Request.ServerVariables("SCRIPT_NAME"))%>’;
2: <img src="/dwstats/send.asp?nojs=1&pnm=<%=(Request.ServerVariables("SCRIPT_NAME"))%>" width="0" height="0" alt="">
Coldfusion:
1: var pageName = ‘<cfoutput>#SCRIPT_NAME#</cfoutput>’;
2: <img src="/dwstats/send.cfm?nojs=1&pnm=<cfoutput>#SCRIPT_NAME#</cfoutput>" width="0" height="0">
Now, whenever you call a page that has this include file, you should see the cutomized tracker in the generated HTML. This way, you never will be able to forget which pages have & don’t have trackers.
Until next time, let the computer do as much work as possible ![]()