PHP code example of goldnead / statamic-leadhub

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

    

goldnead / statamic-leadhub example snippets


'statuses' => [
    'new'        => 'New',
    'contacted'  => 'Contacted',
    'qualified'  => 'Qualified',
    'proposal'   => 'Proposal sent',   // your own
    'won'        => 'Won',
    'lost'       => 'Lost',
    'archived'   => 'Archived',
],

if (! $this->userCan($request, 'manage leadhub opportunities')) {
    $this->authorizeOrFail($request, 'edit leadhub contacts');
}

// config/leadhub.php

'statuses'                                   // available lead statuses
'default_status'                             // status assigned to new contacts
'overwrite_existing_fields_from_submissions' // never overwrite manually edited contacts (default: false)
'store_full_submission_payload'              // attach raw submission to timeline
'timeline_payload_redaction'                 // sensitive keys redacted before storage
'exports.*'                                  // queue threshold, target disk and directory
'features.*'                                 // toggle features (attribution, crm_destinations, CRM-core modules)
'scoring.*'                                  // fallback point table (see Lead scoring)
'click_tracking.*'                           // dedupe window and ignored query parameters
'notifications.*'                            // recipient e-mails, digest time (see Lead assignment)
'attribution.fields'                         // which submission fields map to UTM / referrer / landing page
'crm.destinations'                           // HubSpot / Brevo / webhook targets (see CRM connectors)
'email_normalization.*'                      // how an address is normalised before deduplication
'storage.*'                                  // driver and, for `flat`, the content path

'notifications' => [
    'enabled'    => env('LEADHUB_NOTIFICATIONS', true),  // the master switch
    'recipients' => env('LEADHUB_NOTIFY_EMAILS'),        // comma-separated team inbox(es)
    'digest' => [
        'enabled' => true,
        'time'    => env('LEADHUB_DIGEST_TIME', '08:00'), // server time, daily
    ],
],

'features' => [
    'attribution' => true,
],

'attribution' => [
    'fields' => [
        'utm_source'   => 'utm_source',
        'landing_page' => 'landing_page',
        // 'utm_campaign' => 'campaign',   // ← map your own field name
    ],
],

LeadHub::ingest([...]);                       // resolve or create the contact first

LeadHub::recordRevenue(
    '[email protected]',
    'payments:payment:41',                    // namespaced by whoever contributes it
    1900,
    'EUR',
    now(),
    'statamic-payments',
);

LeadHub::refundRevenue('payments:payment:41', 400);   // the RUNNING total, not one movement
LeadHub::revenueFor($contactId);                      // the ledger behind the totals

use Goldnead\Leadhub\Contracts\TimelineSource;
use Goldnead\Leadhub\Facades\LeadHub;

LeadHub::registerTimelineSource(new class implements TimelineSource { /* key(), available(), entries(), stats(), supersedes() */ });

'features' => [
    'crm_destinations' => true,
],

'crm' => [
    'destinations' => [
        'hubspot' => [
            'driver'   => 'hubspot',
            'enabled'  => true,
            'token'    => env('LEADHUB_HUBSPOT_TOKEN'),  // private-app token
            'triggers' => ['created', 'status_changed'],
        ],
        'brevo' => [
            'driver'   => 'brevo',
            'enabled'  => true,
            'api_key'  => env('LEADHUB_BREVO_KEY'),
            'list_id'  => env('LEADHUB_BREVO_LIST'),      // optional
        ],
        'zapier' => [
            'driver'   => 'webhook',
            'enabled'  => true,
            'url'      => env('LEADHUB_WEBHOOK_URL'),
            'secret'   => env('LEADHUB_WEBHOOK_SECRET'),  // optional HMAC signing
        ],
    ],
],

use Goldnead\Leadhub\Crm\DestinationManager;

app(DestinationManager::class)->extend('salesforce', function (string $key, array $config) {
    return new \App\Leadhub\SalesforceDestination($key, $config);
});

use Goldnead\Leadhub\Facades\LeadHub;

LeadHub::segments();                          // [{ id, name, handle, is_active, members_count }, ...]
LeadHub::segmentMemberIds('qualified-leads'); // ['<contact-uuid>', ...] resolved LIVE from the rules
LeadHub::contactInSegment($contactOrId, 'qualified-leads'); // bool, cheap reactive check

// namespace Goldnead\Leadhub\Events

// Contact lifecycle
LeadHubContactCreated        LeadHubContactUpdated       LeadHubStatusChanged
LeadHubSubmissionAttached    LeadHubNoteAdded            LeadHubTagAdded
LeadHubTagRemoved            LeadHubContactArchived      LeadHubContactDeleted
LeadHubContactsMerged        LeadHubSourceIngested       LeadHubContactScoreChanged
LeadHubEmailLinkClicked

// Follow-ups
LeadHubFollowupSet           LeadHubFollowupCompleted    LeadHubFollowupDue

// Segments
LeadHubContactEnteredSegment LeadHubContactLeftSegment

// CRM-core modules
LeadHubCompanyCreated        LeadHubTaskCreated          LeadHubTaskAssigned
LeadHubTaskCompleted         LeadHubOpportunityCreated   LeadHubOpportunityStageChanged
LeadHubOpportunityWon        LeadHubOpportunityLost

use Goldnead\Leadhub\Events\LeadHubStatusChanged;
use Illuminate\Support\Facades\Event;

Event::listen(LeadHubStatusChanged::class, function (LeadHubStatusChanged $event) {
    // $event->contact, $event->actor, $event->metadata
    MyExternalSystem::sync($event->contact);
});
bash
php artisan vendor:publish --tag=statamic-leadhub --force
bash
php artisan vendor:publish --tag=leadhub-config
bash
php artisan leadhub:followups:digest
bash
php artisan leadhub:brand-integrity            # reports; changes nothing
php artisan leadhub:brand-integrity --repair   # rebuilds the indexes only
bash
php artisan leadhub:stache:warm
php artisan leadhub:stache:warm --clear   # full rebuild
bash
cd /tmp/leadhub-smoketest-{ts}
php please make:user        # create yourself a CP user
php artisan serve            # then visit http://127.0.0.1:8000/cp