1. Go to this page and download the library: Download mbuzz/mbuzz-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/ */
mbuzz / mbuzz-php example snippets
use Mbuzz\Mbuzz;
// Initialize the SDK (typically in your bootstrap/config)
Mbuzz::init([
'api_key' => $_ENV['MBUZZ_API_KEY'],
'debug' => true, // optional, logs API requests
]);
// Initialize from request (reads cookies, captures context)
// Call this early in your request lifecycle, before output
Mbuzz::initFromRequest();
// Track events
Mbuzz::event('page_view', ['url' => 'https://example.com/products']);
Mbuzz::event('add_to_cart', ['product_id' => 'SKU-123', 'price' => 49.99]);
// Track conversions
Mbuzz::conversion('purchase', [
'revenue' => 99.99,
'properties' => ['order_id' => 'ORD-123'],
]);
// Acquisition conversion (marks signup as first touchpoint)
Mbuzz::conversion('signup', [
'user_id' => $user->id,
'is_acquisition' => true,
]);
// Recurring revenue (inherits attribution from acquisition)
Mbuzz::conversion('payment', [
'user_id' => $user->id,
'revenue' => 49.00,
'inherit_acquisition' => true,
]);
// Identify user (link visitor to known user)
Mbuzz::identify($user->id, [
'email' => $user->email,
'name' => $user->name,
'plan' => 'pro',
]);
// Access current IDs
$visitorId = Mbuzz::visitorId();
$userId = Mbuzz::userId();
Mbuzz::init([
'api_key' => 'sk_live_...', // Required: Your Mbuzz API key
'api_url' => null, // Optional: data-resident installs only, see below
'enabled' => true, // Optional: Enable/disable tracking
'debug' => false, // Optional: Log API requests
'timeout' => 5, // Optional: HTTP timeout in seconds
'skip_paths' => ['/admin'], // Optional: Additional paths to skip
'skip_extensions' => ['.pdf'], // Optional: Additional extensions to skip
]);
Mbuzz::init([
'api_key' => 'sk_live_au_...',
'api_url' => 'https://<your region host>/api/v1',
]);
// index.php or bootstrap.php
_key' => $_ENV['MBUZZ_API_KEY']]);
// Returns true when this request WAS POST /_mbuzz/session: the SDK has minted
// the visitor cookie and answered with a 204, so there is nothing to render.
if (Mbuzz::initFromRequest()) {
return;
}
// Your application code...
// app/Providers/AppServiceProvider.php
use Mbuzz\Mbuzz;
public function boot(): void
{
Mbuzz::init([
'api_key' => config('services.mbuzz.key'),
'debug' => config('app.debug'),
]);
}
// app/Http/Kernel.php
protected $middleware = [
// ...
\Mbuzz\Adapter\LaravelMiddleware::class,
];
// config/services.yaml
services:
Mbuzz\Adapter\SymfonySubscriber:
tags: ['kernel.event_subscriber']
// src/Kernel.php or config/packages/mbuzz.php
use Mbuzz\Mbuzz;
Mbuzz::init([
'api_key' => $_ENV['MBUZZ_API_KEY'],
]);
use Slim\Factory\AppFactory;
use Mbuzz\Mbuzz;
use Mbuzz\Adapter\Psr15Middleware;
$app = AppFactory::create();
Mbuzz::init(['api_key' => $_ENV['MBUZZ_API_KEY']]);
$app->add(new Psr15Middleware());
$app->run();
if (Mbuzz::initFromRequest()) { return; }
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.