D
D
desperate_one2021-08-08 02:51:36
PHP
desperate_one, 2021-08-08 02:51:36

How to set up sending orders via API to Yandex.Metrica End-to-End Analytics?

Hey! Has anyone been able to successfully send data to Yandex.Metrica End-to-End Analytics? Doing everything according to their documentation , I send a request as indicated here , at first I received an error 401, after I corrected the request code, I stopped receiving anything at all in response. Maybe someone has already connected and there is a ready-made solution or who can direct what is wrong, I will be very grateful.

$curl_body = array(
        "orders" => array("id" => "32152144",
                "client_uniq_id" => 'подставляю значение полученное через getClientID',
                "client_type" => "CONTACT",
                "create_date_time" => "2020-04-14 13:17:00",
                "update_date_time" => "2020-04-17 16:12:21",
                "finish_date_time" => "2020-04-17 11:59:00",
                "revenue" => 1000,
                "order_status" => "Создан",
                "cost" => 100500,
                "products" => array("Товар А" => 173, "Товар Б" => 146),
                "attribute_values" => array( "channel" => "online", )
        )
    );

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://api-metrika.yandex.net/cdp/api/v1/counter/мойномерсчётчика/data/orders?merge_mode=APPEND',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => json_encode($curl_body),
    ));
    $response2 = curl_exec($curl);
    curl_close($curl);
    echo $response2;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
seopublic, 2022-01-27
@seopublic

There is a ready library: https://github.com/crawler364/yandex-metrika-sdk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question