PHP code example of balfour / laravel-klaviyo

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

    

balfour / laravel-klaviyo example snippets


use App\Models\User;
use Balfour\LaravelKlaviyo\Event;
use Balfour\LaravelKlaviyo\Jobs\PushIdentity;
use Balfour\LaravelKlaviyo\Jobs\TrackEvent;
use Balfour\LaravelKlaviyo\Klaviyo;

$klaviyo = app(Klaviyo::class);

// pushing an identity
// in a real world, this may be a `user` model implementing the `IdentityInterface`
$user = User::find(1);
$klaviyo->pushIdentity($user);

// pushing an identity (using a queue)
$user = User::find(1);
PushIdentity::enqueue($user);

// tracking an event
$user = User::find(1);
$event = new Event(
    'Complete Checkout Step 2',
    [
        'product' => 'Chicken Soup',
        'price' => 'R100.00',
    ]
);
$event->fire($user);
// or
$klaviyo->trackEvent($user, $event);

// tracking an event (using a queue)
$event->enqueue($user);
// or
TrackEvent::enqueue($user, $event);

// in the case that you don't have an identity object, but just an email identifier
$event = new Event('Subscribed To Mailing List');
$event->fire('[email protected]');

// create a mailing list
$klaviyo->createMailingList('My List Name');

// add email to mailing list
$klaviyo->addToMailingList('12345', '[email protected]');

// remove email from mailing list
$klaviyo->removeFromMailingList('12345', '[email protected]');