EMBED
Environment settings in Chatmode.</body>
tag.footer.php
file and paste the script snippet directly before the <?php wp_footer(); ?>
call or the closing </body>
tag.
useEffect
hook in a layout component or the main App component to append the script dynamically only on the client-side. Ensure you handle cleanup.
@chatmode/embed
package within a client-side component. This ensures the embed code is loaded only when needed and integrates well with the framework’s lifecycle and build process.
Steps:
"use client";
in Next.js App Router).useEffect
for Initialization: Inside the component, use a useEffect
hook to dynamically import and initialize the bubble. Also, implement a cleanup function to remove the embed when the component unmounts."YOUR_ENVIRONMENT_ID_FROM_UI"
with the actual Environment ID copied
from your Chatmode Environment settings. Add iconKey
and updatedAt
if you
are using a custom icon uploaded via the UI.@chatmode/embed
module only when needed (e.g., after user interaction or page load completion), though this requires a more complex setup.</body>
is generally good practice.identify
, setContext
) is not supported by the standard Chatmode.initBubble
method.
However, you can programmatically control the chat modal’s state (open, close, toggle) using the object returned by Chatmode.initBubble
. See the Customization Guide for details.
If you need to hide the bubble itself based on page logic, you might need to resort to conditional loading (not adding the script) or CSS overrides (display: none !important;
) targeting the bubble elements (not recommended).