A
A
Alexey Vesnin2018-02-20 19:01:09
PHP
Alexey Vesnin, 2018-02-20 19:01:09

How to transfer UTM tag metric from php redirect to Yandex?

Hello. There is a php redirect script, tell me how to transfer the values ​​of UTM tags from it to Yandex.metric.
So far I've put together the following code:

<?php 

session_start();

$parameters = ['utm_source','utm_medium','utm_campaign', 'utm_term','utm_content','type','source','cost','block','position','keyword','order_id','customer_name','customer_email','customer_phone', 'pincode', 'signature', 'utm','region','ref'];

foreach ($parameters as $param) {
    if (isset($_GET[$param]) && !empty($_GET[$param])) {
        $_SESSION[$param] = strip_tags($_GET[$param]);
    }
}

// Переменные с сессии

$data = array();

    if (isset($_SESSION[$utm_source]) && !empty($_SESSION[$utm_source])) {
        $data['utm_source'] = strip_tags($_SESSION[$utm_source]);
    }
    if (isset($_SESSION[$utm_medium]) && !empty($_SESSION[$utm_medium])) {
        $data['utm_medium'] = strip_tags($_SESSION[$utm_medium]);
    }
    if (isset($_SESSION[$utm_campaign]) && !empty($_SESSION[$utm_campaign])) {
        $data['utm_campaign'] = strip_tags($_SESSION[$utm_campaign]);
    } 
    if (isset($_SESSION[$utm_term]) && !empty($_SESSION[$utm_term])) {
        $data['utm_term'] = strip_tags($_SESSION[$utm_term]);
    } 
    if (isset($_SESSION[$source]) && !empty($_SESSION[$source])) {
        $data['source'] = strip_tags($_SESSION[$source]);
    } 
    if (isset($_SESSION[$utm]) && !empty($_SESSION[$utm])) {
        $data['utm'] = strip_tags($_SESSION[$utm]);
    }
    if (isset($_SESSION[$ref]) && !empty($_SESSION[$ref])) {
        $data['ref'] = strip_tags($_SESSION[$ref]);
    } 



$URL="http://link";
header("Location:$URL");
exit();


?>

The important point is that I need to catch UTM tags at the very moment of the redirect, since when the visitor goes to the second site, there will be no opportunity to put a metric on it.
There is also an idea to write data to mysql

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question