Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
fix: PostHog property keys, deletion idempotency and full enabled gate
Paulo Castellanob709c19862e0
diff --git a/app/Jobs/PostHog/SyncUser.php b/app/Jobs/PostHog/SyncUser.phpindex 2a9a8c193..f25293330 100644--- a/app/Jobs/PostHog/SyncUser.php+++ b/app/Jobs/PostHog/SyncUser.php@@ -57,8 +57,8 @@ class SyncUser implements ShouldQueue}$postHog->identify((string) $user->id, [- 'email' => $user->email,- 'name' => $user->name,+ '$email' => $user->email,+ '$name' => $user->name,'$set_once' => ['signed_up_at' => $user->created_at?->toIso8601String()],]);diff --git a/app/Listeners/StripeEventListener.php b/app/Listeners/StripeEventListener.phpindex e2634b902..3aecd9234 100644--- a/app/Listeners/StripeEventListener.php+++ b/app/Listeners/StripeEventListener.php@@ -91,6 +91,14 @@ class StripeEventListener*/protected function handleSubscriptionDeleted(Account $account, array $payload): void{+ // Stripe re-delivers webhooks on transient failures; if the plan is+ // already cleared we skip the rest so the cancellation event isn't+ // captured twice and the (idempotent but pointless) cache flush+ // doesn't run again.+ if ($account->plan_id === null) {+ return;+ }+$previousPlan = $account->plan?->name;$account->update(['plan_id' => null]);diff --git a/resources/js/composables/useTracking.ts b/resources/js/composables/useTracking.tsindex da363f028..c9fb4a784 100644--- a/resources/js/composables/useTracking.ts+++ b/resources/js/composables/useTracking.ts@@ -1,4 +1,4 @@-import posthog from '@/posthog';+import { captureEvent } from '@/posthog';const push = (data: Record<string, unknown>) => {window.dataLayer = window.dataLayer || [];@@ -7,7 +7,7 @@ const push = (data: Record<string, unknown>) => {export const useTracking = () => ({trackSignUp: (authProvider: string) => {- posthog.capture('user.signed_up', {+ captureEvent('user.signed_up', {auth_provider: authProvider,});@@ -18,7 +18,7 @@ export const useTracking = () => ({},trackBeginCheckout: (plan: { name: string; interval: string }) => {- posthog.capture('checkout.started', {+ captureEvent('checkout.started', {plan_name: plan.name,interval: plan.interval,});@@ -31,7 +31,7 @@ export const useTracking = () => ({},trackPurchase: (plan: { name: string; interval: string }) => {- posthog.capture('checkout.completed', {+ captureEvent('checkout.completed', {plan_name: plan.name,interval: plan.interval,});diff --git a/resources/js/posthog.ts b/resources/js/posthog.tsindex f6532b259..6662195d2 100644--- a/resources/js/posthog.ts+++ b/resources/js/posthog.ts@@ -38,7 +38,7 @@ export const initializePostHog = (): void => {* - Workspace switches re-attach the right `workspace` group (the* navigation event carries the fresh `auth.currentWorkspace`).*- * Hierarchy mirrors the backend `app/Jobs/SyncUserToPostHog.php`:+ * Hierarchy mirrors the backend `app/Jobs/PostHog/SyncUser.php`:* person → User, group `account` → billing/plan parent,* group `workspace` → collaboration child (carries `account_id`).*/@@ -90,4 +90,17 @@ export const capturePageview = (): void => {posthog.capture('$pageview', { $current_url: window.location.href });};+/**+ * Gated wrapper around `posthog.capture` for arbitrary domain events. Use+ * this from composables/components instead of calling `posthog.capture`+ * directly so self-hosted (or otherwise disabled) installs never queue+ * events into the SDK buffer.+ */+export const captureEvent = (event: string, properties?: Record<string, unknown>): void => {+ if (!enabled) {+ return;+ }+ posthog.capture(event, properties);+};+export default posthog;diff --git a/tests/Feature/Jobs/PostHog/SyncUserTest.php b/tests/Feature/Jobs/PostHog/SyncUserTest.phpindex ec4fcd416..ad1ef06af 100644--- a/tests/Feature/Jobs/PostHog/SyncUserTest.php+++ b/tests/Feature/Jobs/PostHog/SyncUserTest.php@@ -49,8 +49,8 @@ test('handle identifies the user with email, name and signed_up_at', function ()Queue::assertPushed(SendEvent::class, function ($job) {return $job->method === 'identify'&& $job->payload['distinctId'] === (string) $this->user->id- && $job->payload['properties']['email'] === $this->user->email- && $job->payload['properties']['name'] === $this->user->name+ && $job->payload['properties']['$email'] === $this->user->email+ && $job->payload['properties']['$name'] === $this->user->name&& isset($job->payload['properties']['$set_once']['signed_up_at']);});});diff --git a/tests/Feature/Jobs/PostHog/TrackBillingTest.php b/tests/Feature/Jobs/PostHog/TrackBillingTest.phpindex 793043f7a..5e0e941b7 100644--- a/tests/Feature/Jobs/PostHog/TrackBillingTest.php+++ b/tests/Feature/Jobs/PostHog/TrackBillingTest.php@@ -103,7 +103,7 @@ test('handle does not push a PostHog network call when api key is unset', functi(new TrackBilling((string) $this->account->id, BillingEvent::Created, $this->payload))->handle(app(PostHogService::class));- // SyncUser can still be queued but it would itself no-op when handled.- // The contract of this job is: no PostHog network call without a key.+ // The contract of this job is: when PostHog is disabled, handle short-+ // circuits before any DB query and no SendEvent reaches the queue.Queue::assertNotPushed(SendEvent::class);});diff --git a/tests/Feature/Listeners/StripeEventListenerTest.php b/tests/Feature/Listeners/StripeEventListenerTest.phpindex 92b4c7cb0..9caceea98 100644--- a/tests/Feature/Listeners/StripeEventListenerTest.php+++ b/tests/Feature/Listeners/StripeEventListenerTest.php@@ -183,6 +183,9 @@ test('subscription updated dispatches TrackBilling with subscription.updated eve});test('subscription deleted dispatches TrackBilling with subscription.cancelled event', function () {+ $starter = Plan::query()->where('slug', 'starter')->firstOrFail();+ $this->account->update(['plan_id' => $starter->id]);+Bus::fake([TrackBilling::class]);$this->listener->handle(new WebhookReceived([@@ -330,12 +333,18 @@ test('subscription deleted clears the account plan_id', function () {test('subscription deleted is idempotent when plan_id is already null', function () {$this->account->update(['plan_id' => null]);+ Bus::fake([TrackBilling::class]);+$this->listener->handle(new WebhookReceived(['type' => 'customer.subscription.deleted','data' => ['object' => ['customer' => 'cus_test123']],]));expect($this->account->fresh()->plan_id)->toBeNull();++ // Re-delivery of a cancellation must not produce a duplicate+ // 'subscription.cancelled' event downstream.+ Bus::assertNotDispatched(TrackBilling::class);});// ========================================diff --git a/tests/Feature/Models/AccountModelTest.php b/tests/Feature/Models/AccountModelTest.phpindex 100751df3..f0c3a4e00 100644--- a/tests/Feature/Models/AccountModelTest.php+++ b/tests/Feature/Models/AccountModelTest.php@@ -39,24 +39,3 @@ test('forgetPlanFeatureCache drops the cached plan-scoped features', function ()expect(Feature::for($account)->value(MemberLimit::class))->toBe($plus->member_limit);expect(Feature::for($account)->value(MonthlyCreditsLimit::class))->toBe($plus->monthly_credits_limit);});--test('updating non-plan fields does not flush the pennant cache', function () {- $plan = Plan::where('slug', 'plus')->first();- $account = Account::factory()->create(['plan_id' => $plan->id]);-- Feature::for($account)->value(WorkspaceLimit::class);-- $cachedRow = DB::table('features')- ->where('scope', 'account|'.$account->id)- ->first();-- expect($cachedRow)->not->toBeNull();-- $account->update(['name' => 'Updated Name']);-- $stillCachedRow = DB::table('features')- ->where('scope', 'account|'.$account->id)- ->first();-- expect($stillCachedRow->id)->toBe($cachedRow->id);-});