Goldilocks Docs
Developers

Widget Integration

Complete guide to adding the Goldilocks widget to your website

This guide covers everything you need to integrate the Goldilocks chat widget into your website.

Basic Integration

Step 1: Get Your API Key

  1. Log into Goldilocks
  2. Go to Installation (click Get Embed Code in the header or in the Essentials section) or Settings > Account
  3. Copy your API key from the API Keys section

Step 2: Add the Script

Add this code before the closing </body> tag:

<script
  src="https://api.goldilocks.chat/goldilocks.js"
  data-key="YOUR_API_KEY"
  async
></script>

Step 3: Verify

Visit your website. You should see the chat bubble (usually bottom-right).

Configuration Options

Data Attributes

Configure using HTML data attributes on the script tag:

<script
  src="https://api.goldilocks.chat/goldilocks.js"
  data-key="YOUR_API_KEY"
  data-position="bottom-right"
  data-theme="light"
  data-open="true"
  data-persona="pers_abc123"
  async
></script>
AttributeDefaultOptions
data-keyRequiredYour API key
data-positionbottom-rightbottom-right, bottom-left
data-themelightlight, dark, auto
data-open-true to auto-open on load
data-persona-Persona public ID (e.g. pers_abc123)
data-user-id-Customer ID for tracking
data-user-email-Customer email
data-user-name-Customer display name

JavaScript Configuration

For dynamic configuration, call gl_chat('init', config) before loading the script, or use gl_chat('init', config) after the script loads:

<script>
  // Option A: Queue init before script loads (script will process queue when it loads)
  (window.gl_chat = window.gl_chat || function(){ (window.gl_chat.q = window.gl_chat.q || []).push(arguments); });
  gl_chat('init', {
    apiKey: 'YOUR_API_KEY',
    position: 'bottom-right',
    theme: 'light',
    autoOpen: false,
    customerId: 'customer-123',
    customerLabel: 'John Smith',
    customerEmail: 'john@example.com'
  });
</script>
<script src="https://api.goldilocks.chat/goldilocks.js" async></script>

Or with data-key for auto-init, then identify after load:

<script src="https://api.goldilocks.chat/goldilocks.js" data-key="YOUR_API_KEY" async></script>
<script>
  window.addEventListener('load', function() {
    gl_chat('identify', { id: 'customer-123', name: 'John Smith', email: 'john@example.com' });
  });
</script>

Platform-Specific Guides

WordPress

Option 1: Theme Editor

  1. Go to Appearance > Theme Editor
  2. Edit footer.php
  3. Add embed code before </body>
  4. Save

Option 2: Plugin

  1. Install "Insert Headers and Footers" plugin
  2. Go to Settings > Insert Headers and Footers
  3. Add code to footer section
  4. Save

Shopify

  1. Go to Online Store > Themes
  2. Click Actions > Edit Code
  3. Open theme.liquid
  4. Find </body> tag
  5. Add embed code before it
  6. Save

With Contact Data (logged-in customer):

<script
  src="https://api.goldilocks.chat/goldilocks.js"
  data-key="YOUR_API_KEY"
  data-user-id="{{ customer.id | default: '' }}"
  data-user-name="{{ customer.name | default: '' }}"
  data-user-email="{{ customer.email | default: '' }}"
  async
></script>

For additional context, call gl_chat('identify', {...}) after the script loads when the customer is available.

Wix

  1. Go to Settings > Custom Code
  2. Click Add Custom Code
  3. Paste embed code
  4. Set:
    • Place code: Body - end
    • Pages: All pages
  5. Apply

Squarespace

  1. Go to Settings > Advanced > Code Injection
  2. Paste code in Footer section
  3. Save

Webflow

  1. Go to Project Settings > Custom Code
  2. Paste in Footer Code section
  3. Publish

Next.js

// app/layout.tsx or pages/_app.tsx
import Script from 'next/script';

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Script
          src="https://api.goldilocks.chat/goldilocks.js"
          data-key="YOUR_API_KEY"
          strategy="lazyOnload"
        />
      </body>
    </html>
  );
}

React

import { useEffect } from 'react';

function App() {
  useEffect(() => {
    const script = document.createElement('script');
    script.src = 'https://api.goldilocks.chat/goldilocks.js';
    script.setAttribute('data-key', 'YOUR_API_KEY');
    script.async = true;
    document.body.appendChild(script);

    return () => {
      document.body.removeChild(script);
    };
  }, []);

  return <div>Your app</div>;
}

With user identification (call after script loads and user is available):

useEffect(() => {
  if (user && typeof window !== 'undefined' && window.gl_chat) {
    gl_chat('identify', { id: user.id, name: user.name, email: user.email });
  }
}, [user]);

Vue

<template>
  <div id="app">
    <!-- Your app -->
  </div>
</template>

<script>
export default {
  mounted() {
    const script = document.createElement('script');
    script.src = 'https://api.goldilocks.chat/goldilocks.js';
    script.setAttribute('data-key', 'YOUR_API_KEY');
    script.async = true;
    document.body.appendChild(script);
  }
};
</script>

Angular

// app.component.ts
import { Component, OnInit, Renderer2 } from '@angular/core';

@Component({
  selector: 'app-root',
  template: '<router-outlet></router-outlet>'
})
export class AppComponent implements OnInit {
  constructor(private renderer: Renderer2) {}

  ngOnInit() {
    const script = this.renderer.createElement('script');
    script.src = 'https://api.goldilocks.chat/goldilocks.js';
    script.setAttribute('data-key', 'YOUR_API_KEY');
    script.async = true;
    this.renderer.appendChild(document.body, script);
  }
}

Conditional Loading

Load Only on Certain Pages

const supportPages = ['/help', '/support', '/faq'];
const currentPath = window.location.pathname;

if (supportPages.some(page => currentPath.startsWith(page))) {
  loadGoldilocks();
}

function loadGoldilocks() {
  const script = document.createElement('script');
  script.src = 'https://api.goldilocks.chat/goldilocks.js';
  script.setAttribute('data-key', 'YOUR_API_KEY');
  document.body.appendChild(script);
}

Exclude Certain Pages

const excludedPages = ['/checkout', '/admin', '/login'];

if (!excludedPages.includes(window.location.pathname)) {
  loadGoldilocks();
}

Load After Delay

setTimeout(loadGoldilocks, 5000); // 5 second delay

Load on Scroll

window.addEventListener('scroll', function onScroll() {
  loadGoldilocks();
  window.removeEventListener('scroll', onScroll);
}, { once: true });

Troubleshooting

Chat Not Appearing

  1. Check API key - Verify key is correct (Settings > Account)
  2. Check domain restrictions - Is your domain allowed?
  3. Check for errors - Open browser console
  4. Check script loading - Network tab in dev tools
  5. Check for conflicts - Other scripts blocking?
  6. Ensure data-key is set - The chat auto-initializes from data-key on the script tag; without it, you must call gl_chat('init', { apiKey: '...' })

Chat in Wrong Position

Use the data-position attribute (bottom-right or bottom-left) on the script tag.

Script Blocked

If Content Security Policy blocks the script, add:

<meta http-equiv="Content-Security-Policy" 
      content="script-src 'self' https://api.goldilocks.chat;">

Performance

Async Loading

Always use async attribute:

<script src="..." async></script>

This prevents blocking page load.

Lazy Loading

For better performance, load after page is ready:

function loadGoldilocks() {
  const script = document.createElement('script');
  script.src = 'https://api.goldilocks.chat/goldilocks.js';
  script.setAttribute('data-key', 'YOUR_API_KEY');
  document.body.appendChild(script);
}

if (document.readyState === 'complete') {
  loadGoldilocks();
} else {
  window.addEventListener('load', loadGoldilocks);
}