This guide shows you how to add Heyo to your Laravel application. Works with Blade templates, Livewire, and Inertia.js.
Add the Heyo script to your main layout file (usually resources/views/layouts/app.blade.php):
<!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>
{{-- Add Heyo before closing head tag --}}
<script src="https://heyo.so/embed/script" defer data-project-id="{{ config('services.heyo.project_id') }}"></script>
</head>
<body>
@yield('content')
</body>
</html>
Add to config/services.php:
return [
// ... other services
'heyo' => [
'project_id' => env('HEYO_PROJECT_ID'),
],
];
Add to .env:
HEYO_PROJECT_ID=YOUR_PROJECT_ID
<script src="https://heyo.so/embed/script" defer data-project-id="{{ config('services.heyo.project_id') }}"></script>
@auth
<script>
window.addEventListener('load', function() {
if (window.HEYO) {
window.HEYO.init({
projectId: '{{ config('services.heyo.project_id') }}',
user: {
name: '{{ auth()->user()->name }}',
email: '{{ auth()->user()->email }}',
id: {{ auth()->user()->id }}
}
});
}
});
</script>
@endauth
For more complex user data:
@auth
<script>
window.addEventListener('load', function() {
if (window.HEYO) {
window.HEYO.init({
projectId: '{{ config('services.heyo.project_id') }}',
user: @json([
'name' => auth()->user()->name,
'email' => auth()->user()->email,
'id' => auth()->user()->id,
'created_at' => auth()->user()->created_at->toIso8601String(),
])
});
}
});
</script>
@endauth
Create app/View/Components/HeyoWidget.php:
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class HeyoWidget extends Component
{
public function render()
{
return view('components.heyo-widget');
}
public function getUserData()
{
if (!auth()->check()) {
return null;
}
return [
'name' => auth()->user()->name,
'email' => auth()->user()->email,
'id' => auth()->user()->id,
];
}
}
Create resources/views/components/heyo-widget.blade.php:
<script src="https://heyo.so/embed/script" defer data-project-id="{{ config('services.heyo.project_id') }}"></script>
@if($userData = $getUserData())
<script>
window.addEventListener('load', function() {
if (window.HEYO) {
window.HEYO.init({
projectId: '{{ config('services.heyo.project_id') }}',
user: @json($userData)
});
}
});
</script>
@endif
Usage in layouts:
<head>
<x-heyo-widget />
</head>
Create app/Providers/HeyoServiceProvider.php:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class HeyoServiceProvider extends ServiceProvider
{
public function boot()
{
Blade::directive('heyo', function () {
return "<?php echo view('heyo::widget'); ?>";
});
$this->loadViewsFrom(__DIR__.'/../../resources/views/heyo', 'heyo');
}
}
Register in config/app.php:
'providers' => [
// ...
App\Providers\HeyoServiceProvider::class,
],
Usage:
<head>
@heyo
</head>
Heyo works seamlessly with Livewire. Add to your layout:
<!DOCTYPE html>
<html>
<head>
@livewireStyles
<script src="https://heyo.so/embed/script" defer data-project-id="{{ config('services.heyo.project_id') }}"></script>
</head>
<body>
@yield('content')
@livewireScripts
</body>
</html>
Control from Livewire components:
// In a Livewire component
public function openChat()
{
$this->dispatchBrowserEvent('open-heyo-chat');
}
<script>
window.addEventListener('open-heyo-chat', () => {
window.HEYO?.show();
});
</script>
For Inertia.js apps, add to resources/js/app.js:
import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/vue3';
createInertiaApp({
resolve: name => require(`./Pages/${name}`),
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
.mount(el);
// Initialize Heyo
if (props.initialPage.props.auth.user) {
window.HEYO?.init({
projectId: import.meta.env.VITE_HEYO_PROJECT_ID,
user: props.initialPage.props.auth.user
});
}
},
});
In your Inertia middleware, share user data:
public function share(Request $request)
{
return array_merge(parent::share($request), [
'auth' => [
'user' => $request->user() ? [
'name' => $request->user()->name,
'email' => $request->user()->email,
] : null,
],
]);
}
For multi-tenant apps, use different Project IDs per tenant:
@php
$projectId = auth()->user()->tenant->heyo_project_id ?? config('services.heyo.project_id');
@endphp
<script src="https://heyo.so/embed/script" defer data-project-id="{{ $projectId }}"></script>
Show chat only on specific routes:
@unless(request()->routeIs('checkout.*'))
<script src="https://heyo.so/embed/script" defer data-project-id="{{ config('services.heyo.project_id') }}"></script>
@endunless
.env for environment-specific IDs@json() directive for safe JSON encoding.envphp artisan config:clear after changes@json() for proper JSON encodingphp artisan view:clear