feat(visitors): определение канала и устройства посетителя
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Services\Tracking\ChannelResolver;
|
||||
|
||||
$r = fn () => new ChannelResolver();
|
||||
|
||||
test('метка utm_source побеждает всё остальное', function () use ($r) {
|
||||
expect($r()->channel(['utm_source' => 'sms'], 'https://yandex.ru/'))->toBe('sms');
|
||||
});
|
||||
|
||||
test('поисковик по referrer → search', function () use ($r) {
|
||||
expect($r()->channel([], 'https://yandex.ru/search/?text=лидерра'))->toBe('search');
|
||||
expect($r()->channel([], 'https://www.google.com/'))->toBe('search');
|
||||
});
|
||||
|
||||
test('hh.ru по referrer → hh', function () use ($r) {
|
||||
expect($r()->channel([], 'https://krasnoyarsk.hh.ru/vacancy/123'))->toBe('hh');
|
||||
});
|
||||
|
||||
test('прочий сайт → referral', function () use ($r) {
|
||||
expect($r()->channel([], 'https://vc.ru/post/1'))->toBe('referral');
|
||||
});
|
||||
|
||||
test('пусто → direct', function () use ($r) {
|
||||
expect($r()->channel([], ''))->toBe('direct');
|
||||
expect($r()->channel([], null))->toBe('direct');
|
||||
});
|
||||
|
||||
test('свой домен в referrer не считается источником → direct', function () use ($r) {
|
||||
expect($r()->channel([], 'https://liderra.ru/'))->toBe('direct');
|
||||
});
|
||||
|
||||
test('устройство по user-agent', function () use ($r) {
|
||||
expect($r()->device('Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X)'))->toBe('phone');
|
||||
expect($r()->device('Mozilla/5.0 (Linux; Android 10; K)'))->toBe('phone');
|
||||
expect($r()->device('Mozilla/5.0 (iPad; CPU OS 17_0)'))->toBe('tablet');
|
||||
expect($r()->device('Mozilla/5.0 (Windows NT 10.0; Win64; x64)'))->toBe('desktop');
|
||||
});
|
||||
Reference in New Issue
Block a user