I
I
Ilya Petrov2019-03-03 12:26:00
PHP
Ilya Petrov, 2019-03-03 12:26:00

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',
];


The name of the form fields was taken from the Bitrix 24 documentation https://dev.1c-bitrix.ru/rest_help/crm/leads/crm_l...

All fields except UTM are transmitted normally.
Everything is fine from my server side, I already dumped this array, there is no empty data in it.

Who faced, unsubscribe.

PS I found a paid plugin that solves this problem - https://www.bitrix24.ru/apps/?app=magnator.lead2bit24
Everything is clearly described in the documentation and an example of PHP code is attached.

UPD: 12/14/2020 - the solution to the problem is described in the article, the Webhook section https://all-service.in.ua/blog/lidy-s-form-v-bitrix24/

Answer the question

In order to leave comments, you need to log in

7 answer(s)
A
Artem Kulygin, 2020-04-29
@AllService

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,"/");

Add it to every page↑.
Then we create invisible fields in the form, with values:
<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']?>">

And in the handler we already receive data, like all other fields:
'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'],

Result:
5ea8c07a0c226249777337.jpeg

O
OldCrazyMan, 2019-05-20
@OldCrazyMan

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

N
Nikolai Pinevich, 2019-05-30
@Afres

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.

D
Dimonchik, 2019-03-03
@dimonchik2013

All fields except UTM are transmitted normally.

and fields with UTM ... (continue sentence)
while in GET / GLOBALS I see
(here dump)

V
Vladislav Istomin, 2019-06-13
@vladsold

i.e. there is no solution? (

M
maddimas, 2020-09-07
@maddimas

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"];

Those. when you enter the site, we write tags in cookies. And after the transition from cookies, we write to GET from where the OK forms take the tags automatically.

I
Ichi Nya, 2021-06-10
@Ichi

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 question

Ask a Question

731 491 924 answers to any question