Putting Analytics in a PHP Redirect Script?

Status
Not open for further replies.

Gyppo

My Balls Convert
Nov 20, 2006
181
2
0
Melbourne, Aus
www.earnersblog.com
I normally handle most of my redirect in a php file, using either a single file or arrays.

Here's an example of lets say wickedfire.php:

Code:
<?php
header( 'Location: http://www.wickedfire.com' );
?>

Does anyone know if it's possible to insert Google Analytics into that PHP file so that it registers everytime someone passes through the redirect.

I know you can track outgoing links by appending onClick="javascript:urchinTracker ('/outgoing/linkname');" into the a href. I just want to know if the above is possible too.
 


Code:
<html>
<head><title> - </title></head>
<body>
<script src=analytics...></script>
<script>
analticsfunction(yourid);
document.write( '<meta refresh... content="0;http...wheretogo.com" />' );
</script>
<meta refresh... content="2;http...wheretogo.com" />
</body>

the document.write would be fired after the script call and as failsave (no js) you fire a normal embeded meta refresh after 2 secs.

but thats just quick & dirty.
 
That may not even work since it's possible that the javascript code from google takes longer than 2 seconds to download.

The best way is to have a continous loop and check to see if a certain analytics function exists. It will exist after the .js has been downloaded by the client. Then after that and after the analyticsfunction(), do the redirect.

And put the meta refresh in a <noscript> tag. (Not sure if that works).
 
Code:
<html>
<head><title> - </title></head>
<body>
<script src=analytics...></script>
<script>
analticsfunction(yourid);
document.write( '<meta refresh... content="0;http...wheretogo.com" />' );
</script>
<noscript>
<meta refresh... content="0;http...wheretogo.com" />
</noscript>
<meta refresh... content="4;http...wheretogo.com" />
</body>
 
Status
Not open for further replies.