Track cancelled subscriptions in PHP

Detect and log cancelled subscriptions in your PHP app, then send events to Operational for reporting and alerting.

What is subscription cancellation tracking in PHP

Tracking cancelled subscriptions in your PHP backend helps you understand user churn and react quickly. For example, if a user decides to cancel your service, logging this event lets you send follow-up offers or analyze cancellation trends.

Using Operational to track cancellations

Operational is an open-source event tracking tool for any tech product. You can send structured events for each cancellation and view them in a dashboard instantly.

Operational in action

Setting up Operational

  1. Go to app.operational.co and sign up for an account.
  2. After signing in, open the API keys page.
  3. Click Create API Key and copy your new key.
  4. Store the API key securely; you will need it in your code.

Sending cancellation events from PHP

<?php
// Initialize API key
$apiKey = 'API_KEY';

// Build the event payload
$payload = [
  'name' => 'subscription cancelled',
  'avatar' => '💔',
  'content' => 'User Jane Doe cancelled subscription 456'
];

// Send event to Operational
$ch = curl_init('https://api.operational.co/events');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authorization: Bearer ' . $apiKey,
  'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

This code sends a subscription cancellation event to Operational so you can track churn in real time.

Conclusion

Using Operational saves you time and effort by handling event collection and display. You can focus on your PHP code without building custom tracking infrastructure. Learn more at Operational or try the playground to test snippets instantly.