> ## Documentation Index
> Fetch the complete documentation index at: https://help.trfyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel

> Install Trfyx analytics in a Laravel application.

# Add Trfyx to your Laravel project

The recommended approach is to add the tracker to the shared Blade layout so it loads on every page.

## Add the tracker to your layout

Open your main layout, commonly `resources/views/layouts/app.blade.php`, and add the tracker inside `<head>`:

```html theme={null}
<script
  defer
  data-website-id="YOUR_TRFYX_PROJECT_ID"
  data-domain="yourdomain.com"
  src="https://app.trfyx.com/script.js"
></script>
```

<Warning>
  Replace `YOUR_TRFYX_PROJECT_ID` with the Website ID from your Trfyx project and `yourdomain.com` with the domain you want to track. Keep the script URL as `https://app.trfyx.com/script.js`. Do not copy another project's Website ID.
</Warning>

The Website ID and domain are public browser-tracking configuration. Never place private API keys or server-side secrets in a Blade template.

## Optional: use environment configuration

If staging and production use different Trfyx projects, you can keep each environment's public tracking values in `.env` and expose them through Laravel configuration.

Add the values to your environment file:

```dotenv theme={null}
TRFYX_WEBSITE_ID=YOUR_TRFYX_PROJECT_ID
TRFYX_DOMAIN=yourdomain.com
```

Create or update `config/trfyx.php`:

```php theme={null}
<?php

return [
    'website_id' => env('TRFYX_WEBSITE_ID'),
    'domain' => env('TRFYX_DOMAIN'),
];
```

Then use those values in your Blade layout while keeping the real tracker URL visible:

```blade theme={null}
<script
  defer
  data-website-id="{{ config('trfyx.website_id') }}"
  data-domain="{{ config('trfyx.domain') }}"
  src="https://app.trfyx.com/script.js"
></script>
```

Replace the environment placeholders with the values from your Trfyx project. Never put secret API credentials in `.env` values that are exposed to the browser.

## Verify installation

1. Deploy the Laravel application.
2. Open the production URL.
3. Navigate through multiple pages.
4. Check the Trfyx dashboard for the incoming visit.

## Troubleshooting

If tracking is missing, verify the layout is actually used by all pages, inspect the browser network panel for blocked requests, check the Website ID and hostname, and make sure your production deployment contains the latest configuration.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.