g1smd - 2:21 am on May 23, 2012 (gmt 0)
Your rule can never run, because ^/$ can never match any real request, other than for example.com// with two slashes. Your rule also performs an internal rewrite and not the required external redirect. $1 is always blank because you haven't captured anything. In short the rule does nothing at all.
As for where you'd put the PHP code. It goes in a separate file. You then "include" that file at the bottom of the page you want to track, and set the $statusCode variable just before you do so. Inside the included file you also have to set the server paths that will be used.