Last active
October 5, 2024 05:25
-
-
Save luckydevilru/a8084d3d4dcf7d0e3fa9aea915a8e87d to your computer and use it in GitHub Desktop.
Создание лида и отправка utm меток в crm bitrix24 битрикс
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// НЕ ЗАБУДЬ ОТПРАВИТЬ НА ОБРАБОТЧИК ДАННЫЕ | |
// order.php?<? echo strstr($_SERVER['REQUEST_URI'],'?') | |
?> | |
<? | |
// ЛОГИРОВАНИЕ В ФАЙЛ | |
function writeToLog($data, $title = '') | |
{ | |
$log = "\n------------------------\n"; | |
$log .= date("Y.m.d G:i:s") . "\n"; | |
$log .= (strlen($title) > 0 ? $title : 'DEBUG') . "\n"; | |
$log .= print_r($data, 1); | |
$log .= "\n------------------------\n"; | |
file_put_contents(getcwd() . '/hook.log', $log, FILE_APPEND); | |
return true; | |
echo "succes"; | |
} | |
// КОНЕЦ ЛОГИРОВАНИЯ | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
$leadData = $_POST['DATA']; | |
$defaults = $_REQUEST; | |
writeToLog($_REQUEST, 'webform'); | |
$queryUrl = 'https://ВАШЛОГИН-В-БИТРИКС.bitrix24.ru/rest/НОМЕР-ПОЛЬЗОВАТЕЛЯ-СОЗДАВШЕГО-ВЕБХУК/КОД-ИЗ-ВЕБХУКА/crm.lead.add.json'; | |
$queryData = http_build_query(array( | |
'fields' => array( | |
'TITLE' => $leadData['TITLE'], | |
'NAME' => $leadData['NAME'], | |
'ASSIGNED_BY_ID' => 10, // ОТВЕТСВЕННЫЙ | |
'UTM_TERM' => $_GET['utm_term'], | |
'UTM_SOURCE' => $_GET['utm_source'], | |
'UTM_MEDIUM' => $_GET['utm_medium'], | |
'HTTP_HOST' => $_SERVER['HTTP_HOST'], | |
'UTM_CAMPAIGN' => $_GET['utm_campaign'], | |
'UTM_CONTENT' => $_GET['utm_content'], | |
'UTM_TERM' => $_GET['utm_term'], | |
'COMMENTS' => $form['COMMENTS'], | |
"STATUS_ID" => "NEW", | |
'COMMENTS' => $leadData['COMMENTS'], | |
"STATUS_ID" => "NEW", | |
"OPENED" => "Y", // ДОСТУПЕН ВСЕМ | |
"PHONE" => array( | |
array( | |
"VALUE" => $leadData['PHONE_MOBILE'], | |
"VALUE_TYPE" => "WORK" | |
) | |
), | |
"EMAIL" => array( | |
array( | |
"VALUE" => $leadData['EMAIL'], | |
"VALUE_TYPE" => "WORK" | |
) | |
) | |
), | |
'params' => array( | |
"REGISTER_SONET_EVENT" => "Y" | |
) | |
)); | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_SSL_VERIFYPEER => 0, | |
CURLOPT_POST => 1, | |
CURLOPT_HEADER => 0, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_URL => $queryUrl, | |
CURLOPT_POSTFIELDS => $queryData | |
)); | |
$result = curl_exec($curl); | |
curl_close($curl); | |
$result = json_decode($result, 1); | |
writeToLog($result, 'webform result'); | |
if (array_key_exists('error', $result)) | |
echo "Ошибка при сохранении лида: " . $result['error_description'] . ""; | |
} | |
?> |
Чёт в обычном формет не передаёт такие переменные, [nnm я и составляю тело запроса не в коде, а в теле json в конструкторе, но одни все поля кроме UTM передаются. Находили ли решения такого? https://skr.sh/sO2YbNMFyZZ
Учите нужный язык программирования или обратитесь к специалисту чтобы он за деньги вам сделал
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Чёт в обычном формет не передаёт такие переменные, [nnm я и составляю тело запроса не в коде, а в теле json в конструкторе, но одни все поля кроме UTM передаются. Находили ли решения такого? https://skr.sh/sO2YbNMFyZZ