Many encounter the issue when UTM tags are not fully transmitted through $_GET
or $_SERVER
. Why does this happen? The issue lies in the specifics of URL parsing.
“I can’t get all UTM tags from the address. `utm_source` and `utm_medium` are being cut off.”
Solutions
- Check the URL. Ensure that all parameters are properly encoded.
- Use
parse_str
. This function will help correctly parse the query string. - Check the server. Some settings may limit the length or format of the URL.
// Получаем текущий url в php $url = ((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $parts = parse_url($url); // делаем из строки массив parse_str($parts['query'], $query); // из массива получаем запрос // выводим utm метки полученные из адресной строки через php echo $query['utm_source']; echo $query['utm_medium']; echo $query['utm_campaign']; echo $query['utm_content'];
The second solution is based on $_SERVER
$qStr = $_SERVER['QUERY_STRING']; parse_str($qStr, $query); echo $query['utm_source']; echo $query['utm_medium']; echo $query['utm_campaign']; echo $query['utm_content'];
This code correctly extracts all UTM tags from the string.
P.S. If the solution doesn’t work, check the server settings.