PHPackages                             ideacrafters/laravel-dittofeed - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. ideacrafters/laravel-dittofeed

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

ideacrafters/laravel-dittofeed
==============================

Laravel SDK for Dittofeed - Open-source customer engagement platform for event tracking, user identification, and marketing automation

0.0.2(5mo ago)045MITPHPPHP ^8.0|^8.1|^8.2|^8.3

Since Nov 19Pushed 5mo agoCompare

[ Source](https://github.com/IdeaCraftersHQ/laravel-dittofeed)[ Packagist](https://packagist.org/packages/ideacrafters/laravel-dittofeed)[ Docs](https://github.com/ideacrafters/laravel-dittofeed)[ RSS](/packages/ideacrafters-laravel-dittofeed/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (13)Versions (4)Used By (0)

Dittofeed Laravel SDK
=====================

[](#dittofeed-laravel-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e190dbaddc50008802d67a9548ffd975c809995a84a573411c5a7001251a6b97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6964656163726166746572732f6c61726176656c2d646974746f666565642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ideacrafters/laravel-dittofeed)[![Total Downloads](https://camo.githubusercontent.com/02a25b2dc408b8e1aa358e3e99a633a9071d734b800248e6beb8905950a38298/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6964656163726166746572732f6c61726176656c2d646974746f666565642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ideacrafters/laravel-dittofeed)[![License](https://camo.githubusercontent.com/f9730b32036e1695492f1c1c1a5dc593b4b34e906a84f144fafbae20393ae41f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6964656163726166746572732f6c61726176656c2d646974746f666565642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ideacrafters/laravel-dittofeed)

Laravel SDK for [Dittofeed](https://dittofeed.com) - an open-source customer engagement platform. This package provides a seamless integration with Laravel, enabling you to easily track user events, send targeted emails, and build automated customer journeys.

Features
--------

[](#features)

- 🚀 **Easy Integration** - Install and configure in minutes
- 🎯 **Event Tracking** - Track user actions, page views, and custom events
- 👤 **User Identification** - Associate users with traits and attributes
- 🔄 **Queue Support** - Async event processing via Laravel's queue system
- 🎨 **Model Traits** - Automatic event tracking for Eloquent models
- 🌐 **Middleware** - Automatic page view tracking
- 🎭 **Facade Support** - Clean, expressive API using Laravel facades
- 🧪 **Testing Utilities** - Fake implementation for testing
- 📊 **Admin API** - Manage templates, segments, and journeys
- 🔐 **Secure** - Built-in authentication and SSL support

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 9.0, 10.0, or 11.0

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require ideacrafters/laravel-dittofeed
```

The package will automatically register itself via Laravel's package auto-discovery.

### Configuration

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=dittofeed-config
```

Add your Dittofeed credentials to your `.env` file:

```
DITTOFEED_WRITE_KEY=your-write-key
DITTOFEED_HOST=https://app.dittofeed.com
DITTOFEED_ADMIN_KEY=your-admin-key # Optional, for admin operations
DITTOFEED_WORKSPACE_ID=your-workspace-id # Optional, for admin operations
```

Quick Start
-----------

[](#quick-start)

### Basic Event Tracking

[](#basic-event-tracking)

```
use Ideacrafters\Dittofeed\Facades\Dittofeed;

// Identify a user
Dittofeed::identify('user-123', [
    'email' => 'john@example.com',
    'name' => 'John Doe',
    'plan' => 'premium',
]);

// Track an event
Dittofeed::track('Purchase Complete', [
    'amount' => 99.99,
    'currency' => 'USD',
    'product' => 'Premium Plan',
], 'user-123');

// Track a page view
Dittofeed::page('Pricing Page', [
    'url' => 'https://example.com/pricing',
    'title' => 'Pricing - Example App',
], 'user-123');
```

### Automatic User Tracking

[](#automatic-user-tracking)

The SDK automatically resolves the current authenticated user:

```
// If user is authenticated, userId is resolved automatically
Dittofeed::track('Button Clicked', [
    'button' => 'Sign Up',
]);
```

Usage Guide
-----------

[](#usage-guide)

### Event Tracking

[](#event-tracking)

#### Identify Users

[](#identify-users)

Associate a user with their traits:

```
Dittofeed::identify('user-123', [
    'email' => 'john@example.com',
    'name' => 'John Doe',
    'plan' => 'premium',
    'created_at' => now()->toIso8601String(),
]);
```

#### Track Events

[](#track-events)

Track custom events with properties:

```
Dittofeed::track('Video Watched', [
    'video_id' => 'abc123',
    'title' => 'Getting Started',
    'duration' => 120,
    'progress' => 0.85,
]);
```

#### Track Page Views

[](#track-page-views)

Track page views (automatically includes URL, referrer, etc.):

```
Dittofeed::page('Product Page', [
    'product_id' => 'prod-123',
    'category' => 'Electronics',
]);
```

#### Track Screen Views

[](#track-screen-views)

For mobile applications:

```
Dittofeed::screen('Home Screen', [
    'screen_id' => 'home',
]);
```

#### Group Users

[](#group-users)

Associate users with groups or organizations:

```
Dittofeed::group('company-abc', [
    'name' => 'Acme Corporation',
    'plan' => 'enterprise',
    'employees' => 500,
]);
```

### Model Integration

[](#model-integration)

Add the `TracksDittofeedEvents` trait to your models for automatic event tracking:

```
use Dittofeed\Laravel\Traits\TracksDittofeedEvents;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Ideacrafters\Dittofeed\Traits\TracksDittofeedEvents;

    use TracksDittofeedEvents;

    // Define which model events to track
    protected $dittofeedEvents = [
        'created' => 'User Registered',
        'updated' => 'Profile Updated',
        'deleted' => 'Account Deleted',
    ];

    // Define which attributes to send as traits
    protected $dittofeedTraits = ['email', 'name', 'plan'];
}
```

Now model events are automatically tracked:

```
$user = User::create([
    'name' => 'John Doe',
    'email' => 'john@example.com',
]);
// Automatically tracks "User Registered" event

$user->update(['plan' => 'premium']);
// Automatically tracks "Profile Updated" event
```

### Automatic Page View Tracking

[](#automatic-page-view-tracking)

Enable automatic page view tracking by adding the middleware to your `app/Http/Kernel.php`:

```
protected $middlewareGroups = [
    'web' => [
        // ... other middleware
        \Ideacrafters\Dittofeed\Middleware\TrackPageViews::class,
    ],
];
```

Or register it as a route middleware alias:

```
protected $routeMiddleware = [
    'dittofeed.track-pages' => \Ideacrafters\Dittofeed\Middleware\TrackPageViews::class,
];
```

Then use it on specific routes:

```
Route::middleware(['dittofeed.track-pages'])->group(function () {
    Route::get('/pricing', [PricingController::class, 'index']);
    Route::get('/features', [FeaturesController::class, 'index']);
});
```

### Automatic Authentication Event Tracking

[](#automatic-authentication-event-tracking)

The SDK automatically tracks user registration, login, and logout events when `auto_track.auth_events` is enabled in the config (enabled by default).

Events tracked:

- `User Registered` - When a user registers
- `User Logged In` - When a user logs in
- `User Logged Out` - When a user logs out

### Queue Support

[](#queue-support)

Enable queue support for asynchronous event processing:

```
DITTOFEED_QUEUE_ENABLED=true
DITTOFEED_QUEUE_NAME=default
DITTOFEED_QUEUE_CONNECTION=redis
```

Events will be dispatched to your queue and processed asynchronously.

### Batch Operations

[](#batch-operations)

Send multiple events in a single request:

```
Dittofeed::batch([
    [
        'type' => 'identify',
        'userId' => 'user-123',
        'traits' => ['email' => 'john@example.com'],
    ],
    [
        'type' => 'track',
        'userId' => 'user-123',
        'event' => 'Purchase Complete',
        'properties' => ['amount' => 99.99],
    ],
]);
```

### Admin API

[](#admin-api)

Access the Admin API for managing templates, segments, and journeys:

```
// Get all templates
$templates = Dittofeed::admin()->getTemplates();

// Create a new segment
$segment = Dittofeed::admin()->createSegment([
    'name' => 'Premium Users',
    'definition' => [
        'type' => 'trait',
        'key' => 'plan',
        'operator' => 'equals',
        'value' => 'premium',
    ],
]);

// Send a broadcast
$broadcast = Dittofeed::admin()->sendBroadcast([
    'name' => 'Product Launch',
    'segmentId' => 'segment-123',
    'templateId' => 'template-456',
]);
```

Testing
-------

[](#testing)

Use the fake implementation in your tests:

```
use Ideacrafters\Dittofeed\Facades\Dittofeed;

public function test_user_registration_tracks_event()
{
    Dittofeed::fake();

    // Perform action that tracks events
    $user = User::create([
        'name' => 'John Doe',
        'email' => 'john@example.com',
    ]);

    // Assert events were tracked
    Dittofeed::assertIdentified('1', ['email' => 'john@example.com']);
    Dittofeed::assertTracked('User Registered');
    Dittofeed::assertTrackCount(1);
}
```

### Available Assertions

[](#available-assertions)

```
Dittofeed::assertIdentified($userId, $traits);
Dittofeed::assertNotIdentified();
Dittofeed::assertTracked($event, $properties, $userId);
Dittofeed::assertNotTracked($event);
Dittofeed::assertPageViewed($name, $properties);
Dittofeed::assertScreenViewed($name, $properties);
Dittofeed::assertGrouped($groupId, $traits, $userId);
Dittofeed::assertIdentifyCount($count);
Dittofeed::assertTrackCount($count);
Dittofeed::assertNothingCalled();
```

Artisan Commands
----------------

[](#artisan-commands)

### Test Your Integration

[](#test-your-integration)

```
php artisan dittofeed:test
```

Sends test events to verify your integration is working correctly.

### Flush Event Queue

[](#flush-event-queue)

```
php artisan dittofeed:flush
```

Manually flush any queued events.

### View Configuration

[](#view-configuration)

```
php artisan dittofeed:stats
```

Display your current Dittofeed configuration and status.

Configuration
-------------

[](#configuration-1)

### Environment Variables

[](#environment-variables)

VariableDescriptionDefault`DITTOFEED_WRITE_KEY`Your write key for the Public API-`DITTOFEED_ADMIN_KEY`Your admin key for the Admin API-`DITTOFEED_HOST`Dittofeed host URL`https://app.dittofeed.com``DITTOFEED_WORKSPACE_ID`Your workspace ID-`DITTOFEED_QUEUE_ENABLED`Enable queue support`false``DITTOFEED_QUEUE_NAME`Queue name`default``DITTOFEED_QUEUE_CONNECTION`Queue connection`null``DITTOFEED_TIMEOUT`HTTP timeout in seconds`30``DITTOFEED_DEBUG`Enable debug logging`false``DITTOFEED_TESTING`Enable testing mode (no events sent)`false`### Auto-Tracking Configuration

[](#auto-tracking-configuration)

```
'auto_track' => [
    'enabled' => true,
    'page_views' => true,     // Track page views automatically
    'auth_events' => true,    // Track login/logout/registration
    'model_events' => false,  // Track model events (opt-in)
],
```

### Context Enrichment

[](#context-enrichment)

Automatically enrich events with contextual data:

```
'context' => [
    'enabled' => true,
    'ip' => true,           // Include IP address
    'user_agent' => true,   // Include user agent
    'timezone' => true,     // Include timezone
    'locale' => true,       // Include locale
],
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom User ID Resolver

[](#custom-user-id-resolver)

Define a custom resolver for the user ID:

```
Dittofeed::resolveUserIdUsing(function () {
    return Auth::user()?->uuid;
});
```

Or set it in the config:

```
'user_id_resolver' => fn() => Auth::user()?->uuid,
```

### Custom Event Properties in Models

[](#custom-event-properties-in-models)

Define custom properties for model events:

```
class Order extends Model
{
    use Ideacrafters\Dittofeed\Traits\TracksDittofeedEvents;

    use TracksDittofeedEvents;

    protected function getDittofeedProperties(): array
    {
        return [
            'order_id' => $this->id,
            'total' => $this->total,
            'status' => $this->status,
            'items_count' => $this->items->count(),
        ];
    }
}
```

### Manual Custom Events in Models

[](#manual-custom-events-in-models)

```
$order->trackCustomEvent('Order Shipped', [
    'tracking_number' => '123ABC',
    'carrier' => 'UPS',
]);
```

Best Practices
--------------

[](#best-practices)

1. **Use Queues** - Enable queue support for better performance
2. **Be Selective** - Only track events that provide value
3. **Name Consistently** - Use consistent event naming (e.g., "Object Action")
4. **Include Context** - Add relevant properties to events
5. **Test Thoroughly** - Use the fake implementation in tests
6. **Secure Keys** - Never commit API keys to version control
7. **Monitor Errors** - Enable debug mode during development

Security
--------

[](#security)

- Never expose your API keys in client-side code
- Use environment variables for configuration
- Enable SSL verification in production
- Review debug logs for sensitive data

Troubleshooting
---------------

[](#troubleshooting)

### Events Not Appearing

[](#events-not-appearing)

1. Check your write key is correct
2. Verify your host URL is correct
3. Enable debug mode to see API responses
4. Run `php artisan dittofeed:test` to test your integration

### Queue Jobs Failing

[](#queue-jobs-failing)

1. Ensure your queue worker is running
2. Check queue logs for errors
3. Verify network connectivity to Dittofeed
4. Increase retry attempts if needed

### Performance Issues

[](#performance-issues)

1. Enable queue support for async processing
2. Use batch operations for multiple events
3. Disable unnecessary auto-tracking
4. Optimize model event tracking

Support
-------

[](#support)

- **Documentation**:
- **Issues**: [GitHub Issues](https://github.com/ideacrafters/laravel-dittofeed/issues)
- **Community**: [Dittofeed Discord](https://discord.gg/dittofeed)

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for recent changes.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

Credits
-------

[](#credits)

- [Amar Neche](https://github.com/amarneche)
- [IdeaCrafters](https://github.com/ideacrafters)
- [All Contributors](https://github.com/ideacrafters/laravel-dittofeed/contributors)

Related Packages
----------------

[](#related-packages)

- [Dittofeed Official SDK](https://github.com/dittofeed/dittofeed) - Official Dittofeed platform
- [Laravel Pixels Manager](https://github.com/ideacrafters/laravel-pixels-manager) - Manage advertising pixels in Laravel

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance70

Regular maintenance activity

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

2

Last Release

168d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7fccd459a4d7a226025511ed967a180d8e259dfd41d3077a4f4b43b63e0a8be6?d=identicon)[monaam\_ic](/maintainers/monaam_ic)

---

Top Contributors

[![amarneche](https://avatars.githubusercontent.com/u/47366103?v=4)](https://github.com/amarneche "amarneche (2 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (2 commits)")[![monaam](https://avatars.githubusercontent.com/u/8881655?v=4)](https://github.com/monaam "monaam (2 commits)")

---

Tags

laravelemailmarketinganalyticssegmentationideacraftersCDPdittofeedcustomer-engagement

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ideacrafters-laravel-dittofeed/health.svg)

```
[![Health](https://phpackages.com/badges/ideacrafters-laravel-dittofeed/health.svg)](https://phpackages.com/packages/ideacrafters-laravel-dittofeed)
```

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[princealikhan/laravel-mautic-api

Free and Open Source Marketing Automation API

415.9k](/packages/princealikhan-laravel-mautic-api)[spatie/laravel-mailcoach-sdk

An SDK to easily work with the Mailcoach API in Laravel apps

41290.2k1](/packages/spatie-laravel-mailcoach-sdk)[juhasev/laravel-ses

Allows you to track opens, deliveries, bounces, complaints and clicked links when sending emails through Laravel and Amazon SES

1710.0k](/packages/juhasev-laravel-ses)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
