How to Place Tracking Codes in a PHP Redirect
If you use Google Analytics to track and analyze website traffic and you use PHP to redirect a visitor to another page, the redirect will not include any tracking data. If you want to include tracking data for the page to which you redirect the website visitor, you can place tracking codes in the PHP redirect by passing them as parameters to the redirect URL.
Instructions
-
-
1
Create a new PHP file with Notepad or an HTML editor for the page you want to redirect.
-
2
Call the PHP header function with an HTTP 301 permanent redirect:
<?php
header( "HTTP/1.1 301 Moved Permanently" );
-
-
3
Call the PHP header function with the redirect URL and the tracking codes as URL parameters:
header( "Location: http://www.new-URL.com?utm_source=source&utm_medium=medium&utm_campaign=campaign" );
?>
-
1
Tips & Warnings
Use output buffering if you issue any kind of message to the user during the redirect.