Background
⌘K

Laravel Integration

Learn how to integrate Affonso affiliate tracking into your Laravel application.

Silvestro
Written by Silvestro
Updated more than a month ago

Laravel Integration

Laravel's Blade templating system combined with environment configuration provides a clean and maintainable way to add tracking scripts across your entire application.

Add tracking script to your Laravel app

Laravel's best practice is to add the tracking script to your main layout template and configure your Program ID through environment variables for better security and flexibility.

  1. Open your main layout file at resources/views/layouts/app.blade.php
  2. Add the tracking script in the <head> section
  3. Configure your Program ID in your environment file:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>@yield('title', config('app.name'))</title>

    <script
      async
      defer
      src="https://affonso.io/js/pixel.min.js"
      data-affonso="{{ config('affonso.program_id') }}"
      data-cookie_duration="{{ config('affonso.cookie_duration') }}"
    ></script>
  </head>
  <body>
    <main>@yield('content')</main>
  </body>
</html>

Find your Program ID →

Create a configuration file at config/affonso.php and add your credentials to your .env file following Laravel's configuration conventions.

Testing

  1. Start your Laravel server: php artisan serve
  2. Visit localhost:8000?atp=test
  3. Check browser DevTools → ApplicationCookiesaffonso_referral
  4. Deploy and verify tracking in your Affonso dashboard

Note: Ensure your session configuration allows cross-domain cookies if using subdomains.

Next Steps

Once installed, you can access affiliate referral data and pass it to your payment provider. Connect your payment provider →

Was this article helpful?

If you still need help, our support team is here for you.

Contact Support
bg

Ready to Scale Your SaaS?

Affonso is the easiest way to launch your own affiliate program. We take care of the technical stuff, so you can focus on growing your business.