I receive a lot of questions from people working on their own SiteCatalyst implementations and I’m always happy to help. One that I got recently is “why is your s_code file a php file”? I figured there were not too many people out there doing it like this or even know about this, so I thought I would help out those that were interested in what the advantages of using server side code to enhance your data collection.
Here are some things I am using it for. I like capturing the IP address of my visitors. I like to track this because I have had problems with spammers, scraper bots and general bad visitors in the past, and I just like keeping my eye on things. Here is the code to capture IP address.
s.eVar17="<?php echo $_SERVER['REMOTE_ADDR']?>";
I also have this matched with the get Val Once plug-in.
s.eVar23="<?php echo $_SERVER['HTTP_USER_AGENT']?>";
Again I match this up with the get Val Once plug-in.
Another thing I like to do is use php to populate the configuration variables of the Time Parting plug-in. The latest version of the plug-in, 2.0, uses specific daylight savings time variables (the 2.0 version is available from the Omniture Help section. The version I host here on the site is the older 1.4 version). The 3 variables that need to be configured for the plug-in are Daylight Savings Time start day for the current year, Daylight Savings Time end day for the current year, and the Current Year. Now all of these can be hard coded, but I’d rather do a little bit of one time coding and never have to worry about it again. Here is how I set those variables using php.
s.dstStart="<?php echo date('m/d/Y', strtotime("Second Sunday March 0"));?>"; s.dstEnd="<?php echo date('m/d/Y', strtotime("First Sunday November 0"));?>"; s.currentYear="<?php echo date('Y');?>";
All of these take advantage of the date() functionality of php. Combine that with a little bit of extra code, and with the fact that I know that daylight savings time always begins the second Sunday of March and ends on the first Sunday of November, I never need to touch those variables again.