PHP code example of da41b94c / traffic-source-capture

1. Go to this page and download the library: Download da41b94c/traffic-source-capture library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

da41b94c / traffic-source-capture example snippets


use Da41b94c\TrafficSource\TrafficSourceCapture;

TrafficSourceCapture::Capture();

$TrafficText = TrafficSourceCapture::GetHuman();     // строка для уведомлений/CRM
$TrafficData = TrafficSourceCapture::GetLeadData();  // массив для БД/CRM

// useCookieBackup=true, ttlSeconds=0 (по умолчанию)
TrafficSourceCapture::Capture(null, null, true, 0);

// Пример: разрешить перезапись first-touch через 30 дней
TrafficSourceCapture::Capture(null, null, true, 2592000);

[
	'traffic_channel' => 'paid',
	'traffic_source' => 'yandex',
	'traffic_medium' => 'cpc',
	'traffic_campaign' => 'roofmaster',
	'traffic_content' => '',
	'traffic_term' => '',
	'traffic_landing' => '/landing',
	'traffic_referrer_host' => 'example.com',
	'traffic_confidence' => 'high',
	'traffic_click_ids' => '{"yclid":"123"}',
	'traffic_details' => 'Реклама — UTM: utm_source=yandex, utm_medium=cpc, utm_campaign=roofmaster; Landing: /landing',
	'traffic_raw' => '{...}'
]

$TrafficData = TrafficSourceCapture::GetLeadData();

$LeadFields = [
	'TITLE' => 'Заявка с сайта',
	'COMMENTS' => $TrafficData['traffic_details'],
	'UTM_SOURCE' => $TrafficData['traffic_source'],
	'UTM_MEDIUM' => $TrafficData['traffic_medium'],
	'UTM_CAMPAIGN' => $TrafficData['traffic_campaign'],
	'UTM_CONTENT' => $TrafficData['traffic_content'],
	'UTM_TERM' => $TrafficData['traffic_term'],
	'UF_TRAFFIC_CHANNEL' => $TrafficData['traffic_channel'],
	'UF_TRAFFIC_CONFIDENCE' => $TrafficData['traffic_confidence'],
	'UF_TRAFFIC_LANDING' => $TrafficData['traffic_landing'],
	'UF_TRAFFIC_RAW' => $TrafficData['traffic_raw'],
];

echo htmlspecialchars($TrafficData['traffic_details'], ENT_QUOTES, 'UTF-8');