Search by

electrictomcat / laravel-google-ads-conversions

electrictomcat

Drop-in offline conversion tracking for Laravel: captures GCLIDs from ad clicks, buffers conversions in cache, and uploads them to the Google Ads API.

Package info

github.com/electrictomcat/laravel-google-ads-conversions

Documentation

pkg:composer/electrictomcat/laravel-google-ads-conversions

Fund package maintenance!

electrictomcat

Statistics

Installs: 1 254

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 1

v1.1.2 2026-09-08 02:00 UTC

This package is auto-updated.

Last update: 2026-09-13 06:04:07 UTC


README

Latest Version on Packagist License: MIT

Production-ready, drop-in offline conversion tracking for Laravel applications. Captures Google Ads click identifiers (gclid, gbraid, wbraid), buffers conversions in cache with zero database lag, and uploads them to the Google Ads API v17/v18.

โšก Need Meta CAPI, TikTok, LinkedIn, Microsoft Ads, or WooCommerce?

If you need multi-channel server-to-server tracking across Meta CAPI (v20.0), TikTok Events API, LinkedIn CAPI, Microsoft Advertising, an in-app live reporting dashboard, or turnkey WordPress & WooCommerce integration, check out OmniSignal Pro.

Key Features

  • ๐ŸŽฏ Full Click Attribution: Captures gclid (Search/Display) as well as gbraid and wbraid (iOS 14.5+ ATT app/web clicks) and maintains attribution across visitor sessions.
  • โšก One-Line Recording: Record conversions from anywhere โ€” controllers, Livewire, queued jobs, Eloquent observers (GoogleAdsConversions::record(...)).
  • ๐Ÿ‡ช๐Ÿ‡บ GDPR, ePrivacy & Consent Mode v2 Ready: Prior-consent cookie gating, automated 90-day retention pruning via Prunable, and explicit Google Consent Mode signals (ad_user_data, ad_personalization).
  • ๐Ÿ”’ Enhanced Conversions for Leads: Strict data minimization with SHA-256 hashed email & phone numbers.
  • ๐Ÿงช First-Class Testing Support: Built-in GoogleAdsConversions::fake() for easy test assertions in your application test suite.
  • ๐Ÿš€ High Performance & Safe Batching: Buffers in cache behind a sharded, lock-guarded dirty set, syncs to database, and uploads in batched requests of up to 2,000 conversions.
  • ๐Ÿ“ฆ Bring Your Own Model: Use the included Lead model or drop HasConversionsTrait onto your existing User, Visitor, or Order models.
  • ๐Ÿ› ๏ธ Artisan Tooling: Dedicated CLI commands for installing, testing credentials against live APIs, syncing cache, and running dry-run uploads.

Requires PHP 8.3+ and Laravel 11, 12, or 13.

Installation

composer require electrictomcat/laravel-google-ads-conversions

Publish configuration and database migration:

php artisan google-ads:install

Run migrations:

php artisan migrate

Configuration

Add your Google Ads API credentials to your .env file:

GOOGLE_ADS_DEVELOPER_TOKEN="your-developer-token"
GOOGLE_ADS_CLIENT_ID="your-client-id.apps.googleusercontent.com"
GOOGLE_ADS_CLIENT_SECRET="your-client-secret"
GOOGLE_ADS_REFRESH_TOKEN="your-refresh-token"
GOOGLE_ADS_CUSTOMER_ID="1234567890" # without hyphens

Usage

1. Register the Click Capture Middleware

Add the middleware to your bootstrap/app.php (Laravel 11+):

->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \ElectricTomCat\GoogleAdsConversions\Http\Middleware\CaptureGclid::class,
    ]);
})

2. Record a Conversion Event

use ElectricTomCat\GoogleAdsConversions\Facades\GoogleAdsConversions;

// Basic lead conversion
GoogleAdsConversions::record('Contact Form');

// Conversion with value and currency
GoogleAdsConversions::record('Demo Booked', 250.00, 'USD');

// Conversion with order ID and Enhanced Conversions (hashed customer data)
GoogleAdsConversions::record(
    eventName: 'Purchase',
    value: 99.00,
    currency: 'USD',
    orderId: 'ORD-9821',
    userIdentifiers: [
        'email' => 'customer@example.com',
        'phone' => '+15551234567',
    ]
);

3. Blade Directive for HTML Forms

Inject hidden click identifiers into your contact or checkout forms:

<form action="/contact" method="POST">
    @csrf
    @googleAdsClickInputs

    <input type="text" name="name" required>
    <button type="submit">Submit</button>
</form>

4. Testing with fake()

use ElectricTomCat\GoogleAdsConversions\Facades\GoogleAdsConversions;

public function test_booking_records_conversion(): void
{
    GoogleAdsConversions::fake();

    $this->post('/book', ['email' => 'test@example.com']);

    GoogleAdsConversions::assertRecorded('Demo Booked', 250.00);
    GoogleAdsConversions::assertNotRecorded('Other Event');
}

๐Ÿ’Ž Need Multi-Platform Tracking?

For Meta CAPI (v20.0), TikTok Events API, LinkedIn Conversions API, Microsoft Advertising, and WooCommerce support, upgrade to OmniSignal Pro.

License

The MIT License (MIT). Please see License File for more information.