Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Drip Laravel Package

glorand/laravel-drip

Laravel 5.7+ integration for the Drip PHP API client. Provides a service provider and facade for easy Drip setup via .env config (account ID, API key, user agent) and quick access to Drip features inside Laravel apps.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require glorand/laravel-drip
    

    Publish the config file:

    php artisan vendor:publish --provider="Glorand\LaravelDrip\DripServiceProvider"
    

    Configure .env with your Drip API credentials:

    DRIP_API_KEY=your_api_key_here
    DRIP_API_SECRET=your_api_secret_here
    
  2. First Use Case: Trigger a Drip campaign for a user when they register:

    use Glorand\LaravelDrip\Facades\Drip;
    
    // After user registration
    $user = User::create([...]);
    Drip::campaigns()->trigger('welcome_sequence', $user->email);
    
  3. Key Files:

    • config/drip.php: API credentials and default settings.
    • app/Providers/DripServiceProvider.php: Service binding (if extending).
    • app/Console/Commands/DripSyncCommand.php: Example for syncing subscribers (if implemented).

Implementation Patterns

Core Workflows

  1. Triggering Campaigns:

    // Trigger a campaign for a single user
    Drip::campaigns()->trigger('campaign_slug', $email);
    
    // Trigger for multiple users (batch)
    $emails = ['user1@example.com', 'user2@example.com'];
    Drip::campaigns()->trigger('campaign_slug', $emails);
    
  2. Subscribing Users:

    // Subscribe with default tags
    Drip::subscribers()->subscribe($email);
    
    // Subscribe with custom tags/metadata
    Drip::subscribers()->subscribe($email, [
        'tags' => ['vip', 'trial_user'],
        'custom_attributes' => ['plan' => 'premium']
    ]);
    
  3. Unsubscribing Users:

    Drip::subscribers()->unsubscribe($email);
    
  4. Syncing Subscribers: Use the DripSyncCommand (if extended) or manually sync via:

    $subscribers = User::all()->pluck('email');
    Drip::subscribers()->sync($subscribers, [
        'tags' => ['active_user'],
        'custom_attributes' => ['last_login' => now()->toDateTimeString()]
    ]);
    
  5. Event Listeners: Attach Drip actions to Laravel events (e.g., registered, created):

    // In EventServiceProvider
    protected $listen = [
        'registered' => [
            'App\Listeners\SubscribeToDrip',
        ],
    ];
    
  6. Middleware for API Routes:

    // Ensure Drip is initialized before handling requests
    Route::middleware(['drip'])->group(function () {
        // Routes requiring Drip
    });
    

Integration Tips

  • Laravel Models: Extend your User model to include Drip methods:

    class User extends Authenticatable {
        public function subscribeToDrip(array $options = []) {
            return Drip::subscribers()->subscribe($this->email, $options);
        }
    }
    
  • Queue Delayed Actions: Offload Drip calls to queues for performance:

    Drip::campaigns()->trigger('campaign_slug', $email)
        ->onQueue('drip')
        ->delay(now()->addMinutes(5));
    
  • Testing: Use mocks for Drip in tests:

    $this->mock(Drip::class)->shouldReceive('campaigns()->trigger')->once();
    

Gotchas and Tips

Pitfalls

  1. API Rate Limits:

    • Drip has rate limits. Batch operations (e.g., sync) may hit limits if not throttled.
    • Fix: Implement retries with exponential backoff or use smaller batches.
  2. Deprecated Laravel Version:

    • The package was last updated in 2018 for Laravel 5.7. Use with caution in newer Laravel versions (6+).
    • Fix: Override service bindings or use a compatibility layer (e.g., laravel-package-compatibility).
  3. Missing Error Handling:

    • The package lacks built-in retry logic for failed API calls.
    • Fix: Wrap Drip calls in try-catch blocks and log errors:
      try {
          Drip::campaigns()->trigger('campaign_slug', $email);
      } catch (\Exception $e) {
          Log::error("Drip trigger failed: " . $e->getMessage());
      }
      
  4. No Webhook Support:

    • The package doesn’t handle Drip webhooks (e.g., for subscriber updates).
    • Fix: Use Laravel’s Http client to manually poll Drip’s API or implement a webhook endpoint.
  5. Config Overrides:

    • The published config may not cover all use cases (e.g., custom endpoints).
    • Fix: Extend the config or override the service provider:
      // In AppServiceProvider
      Drip::extend(function ($app) {
          $app->singleton('drip', function () {
              return new \Glorand\Drip\Client([
                  'api_key' => config('drip.custom_key'),
                  'api_secret' => config('drip.custom_secret'),
                  'endpoint' => config('drip.custom_endpoint'),
              ]);
          });
      });
      

Debugging Tips

  1. Enable API Logging: Add this to config/drip.php:

    'debug' => env('DRIP_DEBUG', false),
    

    Logs will appear in storage/logs/laravel.log.

  2. Validate API Credentials: Test credentials manually via Drip’s API docs or use:

    php artisan drip:test-connection
    

    (If the command doesn’t exist, add it to DripServiceProvider.)

  3. Check HTTP Status Codes: Drip returns non-200 codes for errors (e.g., 400 for invalid emails). Inspect responses:

    $response = Drip::subscribers()->subscribe($email);
    if ($response->failed()) {
        dd($response->errors());
    }
    

Extension Points

  1. Custom Drip Client: Replace the default client by binding a custom instance:

    $this->app->bind('drip', function () {
        return new \Glorand\Drip\CustomClient(config('drip'));
    });
    
  2. Add New Methods: Extend the facade or service provider to add missing Drip features (e.g., suppressions):

    // In DripServiceProvider
    $this->app->afterResolving('drip', function ($drip) {
        $drip->suppressions(function () {
            return new \App\Services\Drip\SuppressionManager($drip);
        });
    });
    
  3. Queue Observers: Observe Drip queue jobs to log or modify payloads:

    // In AppServiceProvider
    DripJob::observed(function ($job) {
        Log::debug('Drip job triggered', ['job' => $job->payload]);
    });
    
  4. Local Development: Use a local Drip mock for testing:

    $this->app->when(Drip::class)
        ->needs(\Glorand\Drip\Client::class)
        ->give(function () {
            return Mockery::mock(\Glorand\Drip\Client::class);
        });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours