-
-
Save kbsali/f2ebf9f4dad87b1203a911c2c04ea352 to your computer and use it in GitHub Desktop.
Simple Sveltekit / Crisp (chat box) integration
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
VITE_CRISP_WEBSITE_ID=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx |
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
<script lang="ts"> | |
import { session } from '$app/stores'; | |
import Crisp from '$lib/components/Crisp.svelte'; | |
let email: string, nickname: string; | |
if ($session.user) { | |
email = $session.user.email; | |
nickname = `${$session.user.firstname} ${$session.user.lastname}`; | |
} | |
</script> | |
{#if $session.user} | |
<Crisp {nickname} {email} /> | |
{/if} | |
<main> | |
<slot /> | |
</main> |
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
<script lang="ts"> | |
import { onMount } from 'svelte'; | |
export let email: string, nickname: string, company: string, phone: string, avatar: string; | |
onMount(() => { | |
window.$crisp = []; | |
window.CRISP_WEBSITE_ID = import.meta.env.VITE_CRISP_WEBSITE_ID; // set in your .env file | |
(function () { | |
const d = document; | |
const s = d.createElement('script'); | |
s.src = 'https://client.crisp.chat/l.js'; | |
s.async = 1; | |
d.getElementsByTagName('head')[0].appendChild(s); | |
})(); | |
if (email) { | |
window.$crisp.push(['set', 'user:email', [email]]); | |
} | |
if (nickname) { | |
window.$crisp.push(['set', 'user:nickname', [nickname]]); | |
} | |
if (company) { | |
window.$crisp.push(['set', 'user:company', [company]]); | |
} | |
if (phone) { | |
window.$crisp.push(['set', 'user:phone', [phone]]); | |
} | |
if (avatar) { | |
window.$crisp.push(['set', 'user:avatar', [avatar]]); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment