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 Widget > Embed or Settings > Security
  3. Copy your API key

Step 2: Add the Script

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

<script
  src="https://widget.goldilocks.chat/embed.js"
  data-api-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:

<script
  src="https://widget.goldilocks.chat/embed.js"
  data-api-key="YOUR_API_KEY"
  data-position="bottom-right"
  data-theme="light"
  data-auto-open="false"
  async
></script>
AttributeDefaultOptions
data-api-keyRequiredYour API key
data-positionbottom-rightbottom-right, bottom-left
data-themelightlight, dark, auto
data-auto-openfalsetrue, false
data-personaDefault personaPersona slug

JavaScript Configuration

For more control, use JavaScript:

<script>
  window.goldilocksSettings = {
    apiKey: 'YOUR_API_KEY',
    position: 'bottom-right',
    theme: 'light',
    autoOpen: false,
    persona: 'support-agent',
    
    // Customer identification
    customerId: 'customer-123',
    customerLabel: 'John Smith',
    
    // Custom context
    context: {
      currentPage: 'checkout',
      cartValue: 99.99
    }
  };
</script>
<script src="https://widget.goldilocks.chat/embed.js" async></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 Customer Data:

<script>
  window.goldilocksSettings = {
    apiKey: 'YOUR_API_KEY',
    customerId: '{{ customer.id | default: "" }}',
    customerLabel: '{{ customer.name | default: "" }}',
    context: {
      customer: {
        email: '{{ customer.email | default: "" }}',
        ordersCount: {{ customer.orders_count | default: 0 }},
        totalSpent: '{{ customer.total_spent | default: 0 }}'
      }
    }
  };
</script>
<script src="https://widget.goldilocks.chat/embed.js" async></script>

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://widget.goldilocks.chat/embed.js"
          data-api-key="YOUR_API_KEY"
          strategy="lazyOnload"
        />
      </body>
    </html>
  );
}

React

import { useEffect } from 'react';

function App() {
  useEffect(() => {
    window.goldilocksSettings = {
      apiKey: 'YOUR_API_KEY',
      customerId: user?.id,
      customerLabel: user?.name
    };

    const script = document.createElement('script');
    script.src = 'https://widget.goldilocks.chat/embed.js';
    script.async = true;
    document.body.appendChild(script);

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

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

Vue

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

<script>
export default {
  mounted() {
    window.goldilocksSettings = {
      apiKey: 'YOUR_API_KEY'
    };

    const script = document.createElement('script');
    script.src = 'https://widget.goldilocks.chat/embed.js';
    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() {
    (window as any).goldilocksSettings = {
      apiKey: 'YOUR_API_KEY'
    };

    const script = this.renderer.createElement('script');
    script.src = 'https://widget.goldilocks.chat/embed.js';
    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://widget.goldilocks.chat/embed.js';
  script.dataset.apiKey = '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

Widget Not Appearing

  1. Check API key - Verify key is correct
  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?

Widget in Wrong Position

Adjust with CSS if needed:

.goldilocks-widget {
  /* Override position */
}

Or use the data-position attribute.

Widget Z-Index Issues

If widget is behind other elements:

window.goldilocksSettings = {
  apiKey: 'YOUR_API_KEY',
  zIndex: 999999
};

Script Blocked

If Content Security Policy blocks the script:

<meta http-equiv="Content-Security-Policy" 
      content="script-src 'self' https://widget.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:

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

Widget Size

The widget script is ~30KB gzipped and loads additional resources on demand.