64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Database\Factories;
|
||
|
|
|
||
|
|
use App\Models\Goal;
|
||
|
|
use App\Models\Website;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
|
|
||
|
|
/** @extends Factory<Goal> */
|
||
|
|
class GoalFactory extends Factory
|
||
|
|
{
|
||
|
|
public function definition(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'website_id' => Website::factory(),
|
||
|
|
'name' => fake()->sentence(2),
|
||
|
|
'type' => 'url_destination',
|
||
|
|
'conditions' => ['path' => '/thank-you', 'match_type' => 'exact'],
|
||
|
|
'default_value' => fake()->randomFloat(2, 1, 100),
|
||
|
|
'is_active' => true,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function urlDestination(string $path = '/thank-you', string $matchType = 'exact'): static
|
||
|
|
{
|
||
|
|
return $this->state([
|
||
|
|
'type' => 'url_destination',
|
||
|
|
'conditions' => ['path' => $path, 'match_type' => $matchType],
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function eventMatch(string $eventName, ?string $category = null): static
|
||
|
|
{
|
||
|
|
return $this->state([
|
||
|
|
'type' => 'event_match',
|
||
|
|
'conditions' => array_filter([
|
||
|
|
'event_name' => $eventName,
|
||
|
|
'event_category' => $category,
|
||
|
|
]),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function duration(int $seconds): static
|
||
|
|
{
|
||
|
|
return $this->state([
|
||
|
|
'type' => 'duration',
|
||
|
|
'conditions' => ['seconds' => $seconds],
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function pagesPerSession(int $count): static
|
||
|
|
{
|
||
|
|
return $this->state([
|
||
|
|
'type' => 'pages_per_session',
|
||
|
|
'conditions' => ['page_count' => $count],
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function inactive(): static
|
||
|
|
{
|
||
|
|
return $this->state(['is_active' => false]);
|
||
|
|
}
|
||
|
|
}
|