Widget Integration
Add the Ziyarn chat widget to any website or framework.
Ziyarn ships three widget looks, all installed with one script tag and one <zy-widget> element. Classic and Glow are a vanilla JavaScript web component that runs in a Shadow DOM for complete style isolation — zero dependencies, works on any website. Modern Sleek loads its full-screen glass chat in a Ziyarn iframe, so it can use a richer React surface without touching the host page's styles.
Basic Installation
Add this code before the closing </body> tag:
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="YOUR_DOMAIN_SLUG"
data-secret="YOUR_EMBED_SECRET"
></zy-widget>Copy the snippet from Dashboard → Domains → Install — it already carries the right slug and secret.
Configuration Options
| Attribute | Type | Default | Description |
|---|---|---|---|
data-slug | string | — | Client-side domain label (required). Namespaces saved conversations and appears in the Modern Sleek iframe URL. |
data-secret | string | — | Embed secret for authentication (required) |
data-title | string | Chat with us | Widget header title |
data-subtitle | string | We usually reply in minutes | Widget header subtitle |
data-color | string | #10b981 | Accent color for the launcher, header and visitor messages (CSS hex value). Modern Sleek uses it for the launcher only. |
data-position | string | bottom-right | Widget position: bottom-right or bottom-left |
data-variant | string | classic | Widget style: classic, glow, or sleek. |
data-api | string | origin of the script | Backend API URL override for Classic and Glow — only needed when the widget is served from a different host than the API. Modern Sleek always uses the Ziyarn origin. |
data-slug is a client-side label for the domain (for example acme-support),
not the domain id. It namespaces the visitor's saved conversation and appears in
the Modern Sleek iframe URL. Authentication is by data-secret, not the slug,
so a URL-safe brand string such as Urban+ also works. There is no
data-greeting attribute: the welcome message is written by the agent, not by
the embed snippet.
:::warning
The data-color attribute expects a CSS hex value (#10b981), NOT Tailwind classes like bg-blue-500.
:::
Widget Variants
Ziyarn ships three looks for the widget:
| Variant | Delivery | What it looks like |
|---|---|---|
classic | Script | A floating chat bubble in the corner of the page |
glow | Script | An aurora panel with a thinking orb while the agent answers |
sleek | Script + iframe | A centered glass card with live tool activity, over a light frosted veil |
Pick one per domain in Dashboard → Domains → Settings → Widget. All three
accept data-variant on the embed element; an unknown value falls back to
classic, so an embed snippet written before variants existed keeps working.
Modern Sleek uses the same <zy-widget> tag as the other variants; its script
adds a launcher and opens the chat in a full-screen iframe.
The variant is a plan feature: the Free plan includes the classic widget only. For script-rendered widgets, a domain whose plan no longer includes its current widget — after a downgrade, for example — falls back to Classic rather than serving something the account no longer includes. Modern Sleek is iframe-backed, so if its plan no longer includes it, the iframe shows an unavailable message instead of silently switching designs.
Modern Sleek
Modern Sleek is a full-screen chat: its glass card floats over a light frosted veil that keeps the host page visible. It uses the same install as Classic and Glow:
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="YOUR_DOMAIN_SLUG"
data-secret="YOUR_EMBED_SECRET"
data-variant="sleek"
></zy-widget>The script renders a launcher bubble. Clicking it opens the chat in a full-screen iframe served by Ziyarn; the chat's close button posts a message back to the script, which hides the frame again. The iframe stays loaded after closing, so reopening it keeps the conversation on screen.
Notes:
- Do not add a separate
<iframe>or click handler;widget.jscreates both. data-coloranddata-positionstyle the launcher. The chat surface has a fixed palette and layout.data-apidoes not change the iframe's API: the iframe is served by, and talks to, the same Ziyarn origin aswidget.js.- If your site sets a CSP, allow
frame-src 'self' https://ziyarn.vercel.appin addition to the script and connect sources below. - The iframe URL carries the domain secret, exactly like the script's API calls.
Signed-in customers
On Business, Enterprise, and Custom plans, a customer who is logged in on your site can keep one private chat across devices. Your server exchanges your domain's identity key for a short-lived pass, then the widget receives it in memory:
document.querySelector("zy-widget").identify(token);
document.querySelector("zy-widget").clearIdentity(); // on logoutNever put the pass in data-*, localStorage, or a URL. The React ZyWidget
and ChatWidget accept identityToken and onIdentityExpired instead. Modern
Sleek forwards the token to its iframe with postMessage, not in the iframe
URL.
See Signed-in Customer Chat for the server endpoint, error codes, and security model.
Platform Guides
HTML / Vanilla JS
The simplest installation. Add the code before </body>:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<!-- Your content -->
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="my-domain"
data-secret="secret_abc123"
data-color="#6366f1"
data-title="Support"
data-subtitle="How can we help?"
></zy-widget>
</body>
</html>React / Next.js
For a React or Next.js app, render the same <zy-widget> element and load
widget.js with next/script. The widget owns its Shadow DOM; React only
renders the custom element. Mount it once — normally in the root layout — so
client-side navigation does not create duplicate widgets.
This is the pattern used by the Urban Plus Next.js storefront.
// components/ziyarn-widget.tsx
"use client";
import Script from "next/script";
type ZiyarnVariant = "classic" | "glow" | "sleek";
export function ZiyarnWidget({
slug,
secret,
variant = "classic",
title = "Chat with us",
subtitle = "We usually reply in minutes",
color = "#10b981",
position = "bottom-right",
}: {
slug: string;
secret: string;
variant?: ZiyarnVariant;
title?: string;
subtitle?: string;
color?: string;
position?: "bottom-right" | "bottom-left";
}) {
return (
<>
<Script
src="https://ziyarn.vercel.app/widget.js"
strategy="afterInteractive"
/>
<zy-widget
data-slug={slug}
data-secret={secret}
data-variant={variant}
data-title={title}
data-subtitle={subtitle}
data-color={color}
data-position={position}
/>
</>
);
}Mount it once in app/layout.tsx:
// app/layout.tsx
import { ZiyarnWidget } from "@/components/ziyarn-widget";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<ZiyarnWidget
slug="urban-plus-2"
secret={process.env.ZIYARN_EMBED_SECRET!}
variant="sleek"
/>
</body>
</html>
);
}The secret is read on the server and passed as a prop, so it does not need a
NEXT_PUBLIC_ prefix. It is still present in the rendered HTML — that is how
the widget authenticates the domain — but it only authorizes widget traffic.
data-api is optional and defaults to the origin of widget.js. Only set it
when the chat API is on a different host.
TypeScript
React needs to know about the custom element. Add this declaration to the app:
// zy-widget.d.ts
import type { JSX } from "react";
declare module "react" {
namespace JSX {
interface IntrinsicElements {
"zy-widget": JSX.IntrinsicElements["div"] & {
"data-slug"?: string;
"data-secret"?: string;
"data-variant"?: "classic" | "glow" | "sleek";
"data-title"?: string;
"data-subtitle"?: string;
"data-color"?: string;
"data-position"?: "bottom-right" | "bottom-left";
"data-api"?: string;
};
}
}
}Common pitfalls
:::warning
Use the domain slug from Dashboard → Domains for consistency. The slug
only labels the client — it namespaces saved conversations and appears in the
Modern Sleek iframe URL — while data-secret authenticates the domain, so a
URL-safe brand string such as Urban+ also works.
Modern Sleek is iframe-backed. If your Next.js app sets a CSP, add
frame-src https://ziyarn.vercel.app (or
frame-src 'self' https://ziyarn.vercel.app) or the launcher will open a
blank frame. See Middleware / CSP Configuration below.
:::
data-variant is read from the element at runtime. The dashboard's saved
widget style only controls the snippet it generates — changing it later does
not rewrite code that is already installed. Keep the variant prop in sync
with the style you want, or copy the generated snippet again.
Do not render a raw <script> tag inside React. Use next/script so the
script loads once and survives client-side navigation.
Vue / Nuxt
In Vue, use <ClientOnly> to prevent SSR issues:
<template>
<ClientOnly>
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="my-domain"
data-secret="secret_abc123"
/>
</ClientOnly>
</template>
<script setup>
const apiUrl = import.meta.env.VITE_API_URL;
</script>For Nuxt, add to app.vue or a layout:
<template>
<NuxtPage />
<ClientOnly>
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="my-domain"
data-secret="secret_abc123"
/>
</ClientOnly>
</template>Svelte / SvelteKit
Use onMount to ensure client-side rendering:
<script>
import { onMount } from "svelte";
let mounted = false;
onMount(() => {
mounted = true;
});
</script>
{#if mounted}
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="my-domain"
data-secret="secret_abc123"
/>
{/if}Angular
In Angular, add to your main component and configure CUSTOM_ELEMENTS_SCHEMA:
// app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "app-root",
template: `
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="my-domain"
data-secret="secret_abc123"
></zy-widget>
`,
})
export class AppComponent {}// app.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
// ...
})
export class AppModule {}WordPress
Add to your theme's footer.php or use a plugin:
<!-- Add before closing </body> tag -->
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="my-domain"
data-secret="secret_abc123"
></zy-widget>Or use a custom HTML widget in your sidebar/footer.
Shopify
Add to your theme's theme.liquid before </body>:
<!-- In themes/YOUR_THEME/layout/theme.liquid -->
{{ content_for_header }}
<!-- Add before closing </body> -->
<script defer src="https://ziyarn.vercel.app/widget.js"></script>
<zy-widget
data-slug="my-domain"
data-secret="secret_abc123"
></zy-widget>Keep the dashboard handy
The dashboard link opens Ziyarn for a specific domain and uses your normal Ziyarn sign-in. It is for you and your staff, not site visitors.
Copy it from Dashboard → Domains → [Domain] → Keep Ziyarn in your site admin, then add it wherever your team already works. If you are signed out, Ziyarn asks you to sign in first.
The link contains only the domain ID — never the embed secret or an API key.
WordPress
Ziyarn does not add anything to your WordPress admin automatically. Add a small must-use plugin so the link survives theme updates.
- Create
wp-content/mu-plugins/if it does not exist. - Create
wp-content/mu-plugins/ziyarn-dashboard.php:
<?php
/**
* Plugin Name: Ziyarn Dashboard Link
* Description: Adds a Ziyarn link to the WordPress admin menu.
*/
defined( 'ABSPATH' ) || exit;
const ZIYARN_DASHBOARD_URL = 'PASTE_YOUR_ZIYARN_DASHBOARD_LINK_HERE';
const ZIYARN_DASHBOARD_PAGE = 'ziyarn-dashboard';
function ziyarn_register_dashboard_menu() {
add_menu_page(
'Ziyarn',
'Ziyarn',
'manage_options',
ZIYARN_DASHBOARD_PAGE,
'ziyarn_render_dashboard_fallback',
'dashicons-format-chat',
58
);
}
add_action( 'admin_menu', 'ziyarn_register_dashboard_menu' );
function ziyarn_redirect_to_dashboard() {
if ( ! isset( $_GET['page'] ) || ZIYARN_DASHBOARD_PAGE !== $_GET['page'] ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
wp_redirect( ZIYARN_DASHBOARD_URL );
exit;
}
add_action( 'admin_init', 'ziyarn_redirect_to_dashboard' );
function ziyarn_render_dashboard_fallback() {
echo '<div class="wrap"><h1>Ziyarn</h1><p><a class="button button-primary" href="' . esc_url( ZIYARN_DASHBOARD_URL ) . '">Open dashboard</a></p></div>';
}- Replace
PASTE_YOUR_ZIYARN_DASHBOARD_LINK_HEREwith the copied link. - Save. A Ziyarn menu item appears for administrators.
The redirect runs on admin_init before WordPress sends the admin page, and
only users with manage_options (administrators) can use it. Do not paste the
snippet into a theme's functions.php; a theme update can remove it.
Custom backends
Add a link to your admin navigation that points to the copied URL. If your admin is a single-page app, open the link in a new tab so the Ziyarn dashboard is not loaded inside your admin's router.
Shopify, Webflow, Wix, Squarespace
These platforms do not let you add arbitrary links to their admin navigation without an app. Keep the dashboard URL as a bookmark or in your password manager for now.
The dashboard link is not a password. Anyone who has it still needs to sign in, and they can only see domains their account already has access to.
Middleware / CSP Configuration
If your site uses Content Security Policy headers, you need to allow the widget domain. Classic and Glow need script-src and connect-src; Modern Sleek also needs frame-src for the iframe origin.
Next.js Middleware
// middleware.ts
import { NextResponse } from "next/server";
export function middleware(request) {
const response = NextResponse.next();
response.headers.set(
"Content-Security-Policy",
"default-src 'self'; script-src 'self' https://ziyarn.vercel.app; connect-src 'self' https://ziyarn.vercel.app; frame-src 'self' https://ziyarn.vercel.app; style-src 'self' 'unsafe-inline';"
);
return response;
}Nginx
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://ziyarn.vercel.app; connect-src 'self' https://ziyarn.vercel.app; frame-src 'self' https://ziyarn.vercel.app; style-src 'self' 'unsafe-inline';";Apache
Header set Content-Security-Policy "default-src 'self'; script-src 'self' https://ziyarn.vercel.app; connect-src 'self' https://ziyarn.vercel.app; frame-src 'self' https://ziyarn.vercel.app; style-src 'self' 'unsafe-inline';"Cloudflare Workers
addEventListener("fetch", (event) => {
const response = await fetch(event.request);
response.headers.set(
"Content-Security-Policy",
"default-src 'self'; script-src 'self' https://ziyarn.vercel.app; connect-src 'self' https://ziyarn.vercel.app; frame-src 'self' https://ziyarn.vercel.app; style-src 'self' 'unsafe-inline';"
);
return response;
});TypeScript Support
All three variants use the same vanilla JS web component. For React / Next.js, use the module augmentation in the React / Next.js guide above. The declarations below cover non-React TypeScript setups.
// ziyarn-widget.d.ts
declare namespace JSX {
interface IntrinsicElements {
"zy-widget": {
"data-slug"?: string;
"data-secret"?: string;
"data-color"?: string;
"data-position"?: "bottom-right" | "bottom-left";
"data-variant"?: "classic" | "glow" | "sleek";
"data-title"?: string;
"data-subtitle"?: string;
"data-api"?: string;
className?: string;
style?: React.CSSProperties;
};
}
}Or use the global declaration:
// global.d.ts
declare global {
namespace JSX {
interface IntrinsicElements {
"zy-widget": {
"data-slug"?: string;
"data-secret"?: string;
"data-color"?: string;
"data-position"?: "bottom-right" | "bottom-left";
"data-variant"?: "classic" | "glow" | "sleek";
"data-title"?: string;
"data-subtitle"?: string;
"data-api"?: string;
};
}
}
}
export {};Troubleshooting
Widget doesn't appear
- Check that the script is loaded (open DevTools → Network tab)
- Verify
data-secretis the domain's embed secret;data-slugonly labels the client - Ensure no CSP headers are blocking the script
Modern Sleek launcher does not open the chat
- Check that the element has
data-variant="sleek"and thatwidget.jsloaded - Confirm
data-slugis non-empty (it labels the client and namespaces saved conversations);data-secretauthenticates the domain - Check the browser console for a frame-ancestors or X-Frame-Options error
- If your site sets a CSP, add
frame-src 'self' https://ziyarn.vercel.app - Check the Network tab for a request to
/embed/YOUR_DOMAIN_SLUG - If the frame opens but says the style is unavailable, confirm the domain's plan and saved widget style include Modern Sleek
Widget appears but doesn't respond
- Check that
data-api(if you set one) points to your backend URL - Verify the backend is running and accessible
- Check browser console for CORS errors
Styles conflict with my site
The widget runs in a Shadow DOM, so styles shouldn't conflict. If you see issues:
- Check for
all: initialorall: revertin your CSS - Ensure no global reset is affecting Shadow DOM elements
Console errors
Open DevTools → Console tab. Common errors:
Failed to fetch— API URL is wrong or backend is downUnauthorized— embed secret is incorrectDomain not found— the slug doesn't exist, or the secret belongs to another domain