PHP code example of jeffersongoncalves / laravel-segment

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

    

jeffersongoncalves / laravel-segment example snippets


// config/segment.php
return [
    'write_key' => env('SEGMENT_WRITE_KEY', ''),
    'access_token' => env('SEGMENT_ACCESS_TOKEN', ''),
    'space_id' => env('SEGMENT_SPACE_ID', ''),
];

use JeffersonGoncalves\Segment\Facades\Segment;

Segment::track('Order Completed', $user->id, [
    'revenue' => 99.90,
    'plan' => 'pro',
]);

Segment::identify($user->id, [
    'email' => $user->email,
    'name' => $user->name,
]);

Segment::page($user->id, 'Pricing', [
    'referrer' => 'google',
]);

Segment::batch([
    ['type' => 'track', 'userId' => $user->id, 'event' => 'Signed Up'],
    ['type' => 'identify', 'userId' => $user->id, 'traits' => ['plan' => 'pro']],
]);

$traits = Segment::profileTraits($user->id);
$events = Segment::profileEvents($user->id);

$traits = Segment::profileTraits($user->id, 'spa_other_space');

try {
    Segment::track('Order Completed', $user->id);
} catch (InvalidArgumentException $e) {
    logger()->error($e->getMessage());
}
bash
php artisan vendor:publish --tag=laravel-segment-config