PHP code example of nocake / msggo

1. Go to this page and download the library: Download nocake/msggo 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/ */

    

nocake / msggo example snippets




oCake\MsgGo\Client;
use NoCake\MsgGo\Client\Exception\ApiException;

// Replace 'YOUR_MSGGO_API_KEY' with your actual API key
$apiKey = 'YOUR_MSGGO_API_KEY';

try {
    // Basic instantiation
    $client = new Client($apiKey);

    // Optionally, override the base API URL
    // $clientWithCustomUrl = new Client($apiKey, ['api_base_url' => 'https://custom.msggo.instance.com']);

    $eventData = [
        'event' => 'my-event',
        'username' => 'john_doe',
        'email' => '[email protected]',
        'source' => 'website_signup_form'
    ];

    // Send an event
    $client->event($eventData);

} catch (\InvalidArgumentException $e) {
    // Handle errors related to invalid arguments (e.g., empty API key)
    echo "Argument Error: " . $e->getMessage() . "\n";
} catch (ApiException $e) {
    // Handle API-specific errors (e.g., authentication failure, validation error)
    echo "API Error: " . $e->getMessage() . "\n";
    echo "Error: " . $e->getError() . "\n";
} catch (\RuntimeException $e) {
    // Handle other runtime errors (e.g., cURL issues, JSON decoding errors not from API)
    echo "Runtime Error: " . $e->getMessage() . "\n";
}