1. Go to this page and download the library: Download code-matic/opencdp-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
code-matic / opencdp-php example snippets
use Codematic\OpenCDP\CDPClient;
use Codematic\OpenCDP\CDPConfig;
use Codematic\OpenCDP\Identifiers;
use Codematic\OpenCDP\SendEmailRequest;
entify('user123', [
'email' => '[email protected]',
'name' => 'John Doe',
'plan' => 'premium'
]);
// Track an event
$client->track('user123', 'purchase_completed', [
'amount' => 99.99,
'item_id' => 'prod-123'
]);
$config = new CDPConfig(
cdpApiKey: 'your-cdp-api-key',
cdpEndpoint: 'https://api.opencdp.io/gateway/data-gateway', // Optional custom endpoint
timeout: 10000, // Request timeout in milliseconds (default: 10000)
debug: false, // Enable debug logging (default: false)
failOnException: false, // Throw exceptions on errors (default: false)
logger: null, // Custom logger instance (LoggerInterface)
sendToCustomerIo: false, // Enable dual-write to Customer.io (default: false)
customerIo: [ // Required if sendToCustomerIo is true
'siteId' => 'your-customer-io-site-id',
'apiKey' => 'your-customer-io-api-key',
'region' => 'us' // or 'eu' for EU data centers
]
);
use Codematic\OpenCDP\SendSmsRequest;
// Using template
$request = new SendSmsRequest(
identifiers: Identifiers::withId('user123'),
transactional_message_id: 'WELCOME_SMS',
message_data: ['name' => 'John']
);
// With body override
$request = new SendSmsRequest(
identifiers: Identifiers::withId('user123'),
transactional_message_id: 'WELCOME_SMS',
body: 'Thank you for joining us!'
);
// Raw SMS (without template)
$request = new SendSmsRequest(
identifiers: Identifiers::withId('user123'),
to: '+1234567890',
from: '+1987654321',
body: 'This is a raw SMS message'
);
$response = $client->sendSms($request);
use Codematic\OpenCDP\SendWhatsAppRequest;
$request = new SendWhatsAppRequest(
identifiers: Identifiers::withId('user123'),
transactional_message_id: 'ORDER_WHATSAPP',
to: '+14155551234', // Optional: overrides the profile phone number
message_data: ['order_number' => '12345'] // {{trigger.order_number}} in the template
);
$response = $client->sendWhatsApp($request);
$config = new CDPConfig(
cdpApiKey: 'your-cdp-api-key',
sendToCustomerIo: true,
customerIo: [
'siteId' => 'your-customer-io-site-id',
'apiKey' => 'your-customer-io-api-key',
'region' => 'us' // or 'eu'
]
);
$client = new CDPClient($config);
// Now all identify, track, and registerDevice calls will send data to both platforms
// Note: Transactional messages (email/push/SMS) are NOT sent to Customer.io to avoid duplicates