Last active
August 30, 2024 21:36
-
-
Save mabsboza/89675099b46935e299cc70d245a1434b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Instalar el paquete de Intercom para PHP | |
Primero, instala el paquete oficial de Intercom para PHP utilizando Composer: | |
<dl> | |
bash | |
composer require intercom/intercom-php | |
</dl> | |
2. Agregar el script de Intercom en tu frontend | |
Para que Intercom funcione en tu aplicación, necesitas agregar el código de JavaScript de Intercom en tu plantilla principal de Laravel. Por lo general, este código se coloca en la sección <head> de tu archivo resources/views/layouts/app.blade.php o en el archivo principal de tu vista. | |
blade | |
<!-- resources/views/layouts/app.blade.php --> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<!-- Otras etiquetas --> | |
<script> | |
window.intercomSettings = { | |
app_id: "{{ env('INTERCOM_APP_ID') }}" | |
@if(Auth::check()) | |
,user_id: "{{ Auth::user()->id }}" | |
,email: "{{ Auth::user()->email }}" | |
,name: "{{ Auth::user()->name }}" | |
,created_at: "{{ strtotime(Auth::user()->created_at) }}" | |
@endif | |
}; | |
</script> | |
<script> | |
(function(){ | |
var w=window;var ic=w.Intercom; | |
if(typeof ic==="function"){ | |
ic('reattach_activator');ic('update',intercomSettings); | |
}else{ | |
var d=document;var i=function(){i.c(arguments)};i.q=[]; | |
i.c=function(args){i.q.push(args)};w.Intercom=i; | |
var l=function(){var s=d.createElement('script'); | |
s.type='text/javascript';s.async=true; | |
s.src='https://widget.intercom.io/widget/{{ env('INTERCOM_APP_ID') }}'; | |
var x=d.getElementsByTagName('script')[0]; | |
x.parentNode.insertBefore(s,x);}; | |
if(w.attachEvent){w.attachEvent('onload',l);} | |
else{w.addEventListener('load',l,false);} | |
} | |
})(); | |
</script> | |
</head> | |
<body> | |
<!-- Contenido de la aplicación --> | |
</body> | |
</html> | |
3. Configurar las variables de entorno | |
Agrega tu APP_ID de Intercom al archivo .env de tu aplicación Laravel: | |
env | |
INTERCOM_APP_ID=tu_intercom_app_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment