Skip to content

Instantly share code, notes, and snippets.

@Leon2110
Last active February 12, 2022 22:00
Show Gist options
  • Save Leon2110/281a7e3271aef6df30188bfc72df3709 to your computer and use it in GitHub Desktop.
Save Leon2110/281a7e3271aef6df30188bfc72df3709 to your computer and use it in GitHub Desktop.
UTM ЮТМ #php
// Функция из ссылки извлекает ютм и отдает массив
<?php
$requestUrl = 'https://site.ru/?utm_source=yandex&utm_medium=cpc&utm_campaign=context&utm_content=kupit_corobku&utm_term=%D0%BA%D1%83%D0%BF%D0%B8%D1%82%D1%8C+%D0%BA%D0%BE%D1%80%D0%BE%D0%B1%D0%BA%D0%B8+%D0%B4%D0%BB%D1%8F+%D0%BE%D0%B1%D1%83%D0%B2%D0%B8';
function getUTM($url) {
$params = [];
$utm = [];
$params_tmp = parse_url($url);
$params_tmp = explode('&', $params_tmp['query']);
foreach($params_tmp as $param) {
list($key, $val) = array_map('trim', explode('=', $param));
if($key != '' && $val != '') {
$params[$key] = $val;
$utm[$key] = urldecode($val);
}
}
return $utm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment