Answer the question
In order to leave comments, you need to log in
How to transfer UTM tags to Bitrix 24 CRM using PHP?
I transfer data from site forms to Bitrix 24 CRM,
the data array looks like this
$postData = [
'TITLE' => 'Заявка с сайта ' . $url,
'NAME' => $name,
'PHONE_MOBILE' => $phone,
'COMMENTS' => 'Источник заявки: ' . $source,
'UTM_CAMPAIGN' => 'campaign',
'UTM_CONTENT' => 'content',
'UTM_MEDIUM' => 'medium',
'UTM_SOURCE' => 'source',
'UTM_TERM' => 'term',
];
Answer the question
In order to leave comments, you need to log in
So, first you need to write utm to the $_cookie array so that when you go to other pages, the values \u200b\u200bare not lost, this code is responsible for this:
if(isset($_GET["utm_source"])) setcookie("utm_source",$_GET["utm_source"],time()+3600*24*30,"/");
if(isset($_GET["utm_medium"])) setcookie("utm_medium",$_GET["utm_medium"],time()+3600*24*30,"/");
if(isset($_GET["utm_campaign"])) setcookie("utm_campaign",$_GET["utm_campaign"],time()+3600*24*30,"/");
if(isset($_GET["utm_content"])) setcookie("utm_content",$_GET["utm_content"],time()+3600*24*30,"/");
if(isset($_GET["utm_term"])) setcookie("utm_term",$_GET["utm_term"],time()+3600*24*30,"/");
<input name="utm-source" type="hidden" value="<?=$_COOKIE['utm_source']?>">
<input name="utm-medium" type="hidden" value="<?=$_COOKIE['utm_medium']?>">
<input name="utm-compaign" type="hidden" value="<?=$_COOKIE['utm_compaign']?>">
<input name="utm-content" type="hidden" value="<?=$_COOKIE['utm_content']?>">
<input name="utm-term" type="hidden" value="<?=$_COOKIE['utm_term']?>">
'UTM_SOURCE' => $_POST['utm-source'],
'UTM_MEDIUM' => $_POST['utm-medium'],
'UTM_CAMPAIGN' => $_POST['utm-campaign'],
'UTM_CONTENT' => $_POST['utm-content'],
'UTM_TERM' => $_POST['utm-term'],
Also the solution of the given question interests
All fields, except UTM are transferred normally. The name of the form fields was taken from the Bitrix 24 documentation
I spent 3 hours looking for a solution, but did not find it, apparently, these variables are not supported by Bitrix through the REST API.
I changed it to WebHook, UTM tags are supported there and analytics is considered. For my case, a webhook is even more convenient.
Here is a good article on which I switched from REST to Webhook.
All fields except UTM are transmitted normally.
For the Open Line shapes, I did this:
if(isset($_GET["utm_source"])) setcookie("utm_source",$_GET["utm_source"],time()+3600*24*30,"/");
if(isset($_GET["utm_medium"])) setcookie("utm_medium",$_GET["utm_medium"],time()+3600*24*30,"/");
if(isset($_GET["utm_campaign"])) setcookie("utm_campaign",$_GET["utm_campaign"],time()+3600*24*30,"/");
if(isset($_GET["utm_content"])) setcookie("utm_content",$_GET["utm_content"],time()+3600*24*30,"/");
if(isset($_GET["utm_term"])) setcookie("utm_term",$_GET["utm_term"],time()+3600*24*30,"/");
if(isset($_COOKIE["utm_source"]) and !isset($_GET["utm_source"])) $_GET["utm_source"] = $_COOKIE["utm_source"];
if(isset($_COOKIE["utm_medium"]) and !isset($_GET["utm_medium"])) $_GET["utm_medium"] = $_COOKIE["utm_medium"];
if(isset($_COOKIE["utm_campaign"]) and !isset($_GET["utm_campaign"])) $_GET["utm_campaign"] = $_COOKIE["utm_campaign"];
if(isset($_COOKIE["utm_content"]) and !isset($_GET["utm_content"])) $_GET["utm_content"] = $_COOKIE["utm_content"];
if(isset($_COOKIE["utm_term"]) and !isset($_GET["utm_term"])) $_GET["utm_term"] = $_COOKIE["utm_term"];
Maybe someone needs it, it works for me like this:
update_bitrix_entity('deal', 13,array('UTM_SOURCE' =>'NEW'));
function update_bitrix_entity($entity, $id, $fiels = array())
{
if (!in_array($entity, array('lead', 'deal', 'contact', 'company')))
{
return false;
}
$name = "crm.{$entity}.update";
$post = array(
'id' => $id,
'fields' => $fiels);
$ret = bitrix::call($name, $post);
return $ret;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question