Code Examples
Practical code examples demonstrating common Alhena Website SDK integration patterns.
This section contains ready-to-use code examples for common Alhena chat widget integration scenarios. Each example includes complete, working code that you can adapt for your website.
Available Examples
Customize AI responses based on A/B test groups
Personalize answers for test vs control users
Automatically close the widget after human transfer
Clean up UI after support handoff
Switch to another support tool on human transfer
Use Freshworks, Zendesk, etc. for human agents
Replace the built-in launcher and nudge with your own
Match chat entry points to your design system
Customize how product prices are displayed
Currency conversion, variant-aware pricing
Track cart and checkout events in WooCommerce
E-commerce revenue attribution
Add an AI search button to Shopify predictive search
Send storefront search queries into the widget
Quick Start Template
All examples build on this basic setup:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Your Page</title>
</head>
<body>
<!-- Your page content -->
<!-- Alhena SDK -->
<script>
document.gleenConfig = {
company: "your-company-key",
apiBaseUrl: "https://app.alhena.ai",
};
</script>
<script src="https://app.alhena.ai/sdk/gleenWidget.js"></script>
<!-- Your custom integration code -->
<script>
// Event handlers and customizations go here
</script>
</body>
</html>Example Categories
Widget Control
Learn how to programmatically control the chat widget:
Scroll-Triggered Widget - Delay widget display until user engagement
Custom Launcher & Nudge UI - Build your own launcher and nudge driven by the standard nudge logic
Open/close based on user actions
Toggle widget from custom buttons
Human Agent Handoff
Handle transitions from AI to human support:
Auto-Close After Handoff - Clean up after support transfer
Human Handoff Widget - Integrate with external helpdesks
Localization & Personalization
Support multiple languages and personalized experiences:
A/B Test Guidelines - Customize AI responses for test vs control groups
Internationalization - Configure UI language
E-commerce
Customize product display and track revenue:
Price Conversion - Format prices with currency conversion or variant-aware pricing
WooCommerce Revenue Tracking - Implement cart and checkout tracking
Shopify Search Button - Hand storefront search queries to the chat widget
Need More Examples?
Check these related documentation pages:
JavaScript API - Complete method reference with examples
Events - Event handling examples
Styles API - Visual customization examples
Custom Data - User personalization examples
A/B Testing - Experiment setup examples
Last updated