Files
analytics/database/factories/AnalyticsSessionFactory.php
2026-03-24 21:12:21 +01:00

49 lines
1.4 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\AnalyticsSession;
use App\Models\Visitor;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/** @extends Factory<AnalyticsSession> */
class AnalyticsSessionFactory extends Factory
{
public function definition(): array
{
$started = now()->subMinutes(fake()->numberBetween(1, 60));
return [
'website_id' => Website::factory(),
'visitor_id' => Visitor::factory(),
'uid' => Str::random(32),
'started_at' => $started,
'ended_at' => $started->copy()->addSeconds(fake()->numberBetween(10, 600)),
'duration' => fake()->numberBetween(10, 600),
'is_bounce' => false,
'entry_page' => '/',
'exit_page' => '/about',
'pages_count' => fake()->numberBetween(1, 10),
'ip_address' => fake()->ipv4(),
'referrer_url' => null,
'referrer_domain' => null,
'utm_source' => null,
'utm_medium' => null,
'utm_campaign' => null,
'utm_term' => null,
'utm_content' => null,
];
}
public function bounce(): static
{
return $this->state([
'is_bounce' => true,
'pages_count' => 1,
'duration' => 0,
]);
}
}