- Refactor WorkspacePolicy to use pivot role instead of workspace.user_id - Add manageBilling policy (owner only) to BillingController - Fix ApiKeyController authorization (view → manageTeam for store/destroy) - Fix WorkspaceInviteController using workspace.user_id for owner checks - Fix WorkspaceController settings is_owner using workspace.user_id - Create PostAction enum for UpdatePost/PostController action strings - Create ApiToken\Status enum - Add User::SUBSCRIPTION_NAME constant, replace all hardcoded 'default' - Convert wantsEmailFor to accept NotificationType enum - Convert all $data[] to data_get() across publishers, controllers, jobs - Fix SocialLoginController callback missing try/catch - Fix SocialController::toggleActive missing workspace null check - Fix UpdatePost NPE on meta merge when postPlatform not found - Remove HTML5 required attributes from form inputs - Convert function declarations to arrow functions in Vue components - Replace hardcoded URLs with Wayfinder route helpers - Replace new Date() with dayjs - Add 16 new test files covering policies, authorization, publishing
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Jobs\SendPostHogEvent;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class PostHogService
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $properties
|
|
*/
|
|
public function capture(string $distinctId, string $event, array $properties = []): void
|
|
{
|
|
$this->dispatch('capture', [
|
|
'distinctId' => $distinctId,
|
|
'event' => $event,
|
|
'properties' => $properties,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $properties
|
|
*/
|
|
public function identify(string $distinctId, array $properties = []): void
|
|
{
|
|
$this->dispatch('identify', [
|
|
'distinctId' => $distinctId,
|
|
'properties' => $properties,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $properties
|
|
*/
|
|
public function groupIdentify(string $groupType, string $groupKey, array $properties = []): void
|
|
{
|
|
$this->dispatch('groupIdentify', [
|
|
'groupType' => $groupType,
|
|
'groupKey' => $groupKey,
|
|
'properties' => $properties,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $payload
|
|
*/
|
|
private function dispatch(string $method, array $payload): void
|
|
{
|
|
if (! config('services.posthog.api_key')) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
SendPostHogEvent::dispatch([
|
|
['method' => $method, 'payload' => $payload],
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
Log::warning('PostHogService: failed to dispatch event', ['method' => $method, 'error' => $e->getMessage()]);
|
|
}
|
|
}
|
|
}
|