PHP code example of justinholtweb / craft-leads

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

    

justinholtweb / craft-leads example snippets




return [
    'autoInjectScript' => true,
    'defaultButtonColor' => '#3b82f6',
    'defaultBackgroundColor' => '#ffffff',
    'dataRetentionDays' => 365,
    'enableHoneypot' => true,
    'rateLimitPerMinute' => 5,
];

use justinholtweb\leads\events\PopupEvent;
use justinholtweb\leads\events\SubmissionEvent;

// After a popup is saved
Event::on(Popup::class, Popup::EVENT_AFTER_SAVE, function (PopupEvent $event) {
    // $event->popup, $event->isNew
});

// After a submission is created
Event::on(Submissions::class, 'afterSubmit', function (SubmissionEvent $event) {
    // $event->submission
});

use justinholtweb\leads\Plugin;
use justinholtweb\leads\elements\Popup;

// Get a popup by ID
$popup = Plugin::getInstance()->popups->getById(123);

// Query active popups for a URL
$popups = Plugin::getInstance()->popups->getActivePopupsForPage('/blog');

// Record a submission
Plugin::getInstance()->submissions->submit(
    popupId: 123,
    email: '[email protected]',
    name: 'Jane Doe',
);

// Get analytics
$stats = Plugin::getInstance()->analytics->getOverviewStats('2025-01-01', '2025-12-31');