Customize the chat widget with HTML and JavaScriptUpdated 17 minutes ago
Who can use this feature?
Advanced HTML and JavaScript customization lets you extend the Gorgias chat widget beyond what's available in the settings — things like controlling when the widget appears, pre-filling messages, hiding the widget on specific pages, or injecting custom CSS. This article explains how the customization layer works and where to place your code so it runs in the right order.
How HTML and JavaScript customization works
The Gorgias chat widget exposes a JavaScript API through a global object called GorgiasChat. Once the widget is loaded on your page, you can call methods on this object to control widget behavior programmatically — opening or closing the widget, hiding it on mobile, capturing a customer's email, sending a message on their behalf, and more.
Because the widget loads asynchronously, you can't call GorgiasChat methods the moment your page loads. You first need to wait for the widget to finish initializing. The recommended way to do this is:
1var initGorgiasChatPromise = (window.GorgiasChat)2 ? window.GorgiasChat.init()3 : new Promise(function (resolve) {4 window.addEventListener('gorgias-widget-loaded', function () { resolve(); })5 });67initGorgiasChatPromise.then(function () {8 // Your custom code goes here9});10
This pattern handles two cases: if GorgiasChat is already present on the window (because the widget loaded before your script ran), it calls init() directly; if not, it waits for the gorgias-widget-loaded event to fire before proceeding. You should use this wrapper for all customizations.
Where to place custom code
All custom scripts must be placed after the Gorgias chat installation snippet, within the <body> tags of your page. The order matters — your script needs the widget's bundle loader to be present on the page before it runs, and the init() promise handles the rest.
Your installation snippet looks like one of these:
1<!-- Version 2 -->2<script id="gorgias-chat-widget-install-v2"3 src="https://config.gorgias.chat/gorgias-chat-bundle-loader.js?applicationId=XXXXX">4</script>56<!-- Version 3 -->7<script id="gorgias-chat-widget-install-v3"8 src="https://config.gorgias.chat/bundle-loader/XXXXXXXXXXXXXXXXXXXXXXXXXX">9</script>10
Your custom <script> tag goes directly after this, still inside <body>:
1<script id="gorgias-chat-widget-install-v3"2 src="https://config.gorgias.chat/bundle-loader/XXXXXXXXXXXXXXXXXXXXXXXXXX">3</script>45<script>6var initGorgiasChatPromise = (window.GorgiasChat)7 ? window.GorgiasChat.init()8 : new Promise(function (resolve) {9 window.addEventListener('gorgias-widget-loaded', function () { resolve(); })10 });1112initGorgiasChatPromise.then(function () {13 // Your custom code goes here14});15</script>16
On Shopify stores
Shopify stores have two options depending on whether you want the customization to apply globally or only to specific pages.
To apply customization globally (all pages), add your custom script to your store's theme.liquid file:
- From the Shopify admin, click Online Store in the left sidebar.
- Click Themes.
- Next to your active theme, click the three dots icon, then select Edit code.
- In the menu, locate Layout, then select theme.liquid.
- Find your Gorgias chat installation snippet in the file.
- Paste your custom
<script>tag immediately after the installation snippet, before the closing</body>tag. - Click Save.
To apply customization to a specific page only, add your custom script to that page's content area using Shopify's HTML editor:
- From the Shopify admin, select Online Store in the left sidebar, then click Pages.
- Select the page you want to edit from the list.
- In the Content area, click the Show HTML icon (the
<>button). - Paste your custom
<script>tag into the HTML view. - Click Save.
On BigCommerce stores
BigCommerce handles <script> tags and non-script code (like CSS overrides) differently.
To add script-based customizations, use the Manage Code feature in BigCommerce:
- From the BigCommerce control panel, go to Manage Code.
- Add your custom
<script>tag as a new script entry. - Save your changes.
To add non-script customizations — such as style overrides that use a <style> tag instead of a <script> tag:
- From the BigCommerce control panel, go to Theme Manager.
- Click Edit Theme next to your active theme.
- Locate the home.html file.
- Add your custom code to the file.
- Save your changes.
Available API methods
The GorgiasChat object exposes a number of methods you can call inside the init() callback. The most commonly used ones are:
GorgiasChat.open()— opens the chat windowGorgiasChat.close()— closes the chat windowGorgiasChat.isOpen()— returnstrueif the chat window is currently openGorgiasChat.hideOnMobile(true)— hides the widget on mobile devicesGorgiasChat.hideOutsideBusinessHours(true)— hides the widget when outside business hoursGorgiasChat.isBusinessHours()— returnstrueif the current time is within configured business hoursGorgiasChat.isChatOnline()— returnstrueif agents are currently onlineGorgiasChat.captureUserEmail('[email protected]')— associates an email address with the current chat sessionGorgiasChat.sendMessage('Your message here')— sends a message on behalf of the visitorGorgiasChat.setCurrentInput('Hello!')— pre-fills the chat input fieldGorgiasChat.updateTexts({})— overrides default label text in the widgetGorgiasChat.setPosition(position)— sets the widget's position on the pageGorgiasChat.disableAttachments()— disables the file attachment optionGorgiasChat.disableSegment()— disables Segment analytics trackingGorgiasChat.setShouldOpenLinksInNewPage(true)— forces links in the chat to open in a new tab
To see example code for each of these methods, see our HTML snippets for chat customization article.
FAQ
I'm getting "Uncaught ReferenceError: GorgiasChat is not defined" — what does that mean?
This error means either the Gorgias chat installation snippet is missing from the page, or your custom script is running before the chat bundle has loaded. Make sure your custom <script> tag appears after the installation snippet in the HTML, and that you're using the init() promise wrapper rather than calling GorgiasChat methods directly.
Also check that your installation snippet has the correct script id: gorgias-chat-widget-install-v2 for version 2 snippets, or gorgias-chat-widget-install-v3 for version 3 snippets. If you recently switched from Quick installation on Shopify, check the order of scripts in your theme files — a re-install can place the Gorgias snippet in a position that interferes with custom code that was there before.