I have a short URL website like Bitly which currently redirect users with PHP from my site to a site of their choice. I want to add Google Analytics to the redirect pages but I am stuck on the problem where Javascript is run after the PHP code is executed so it wont work.
Bellow is the last part of the PHP code that redirects users from the short URL to the URL they shortend. I wonder if there is anyway to make this work OR change my code somehow so that Google Analytics can be executed either with PHP or something else that can do the "redirection"?
$shortUrlObj
contains the short url code. If the short url is https://example.com/1234
$shortUrlObj
contains 1234
. fullUrl
is the website destination they choose to shorten. So if the user shortened https://stackexchange.com
, fullUrl
contains https://stackexchange.com
switch ($redirect)
{
default:
header('HTTP/1.1 302 Moved Temporarily');
redirect($shortUrlObj->fullUrl);
break;
}