Docs
Installation Script

Installation Script

Complete guide to adding ai4shops.com to your website. Universal JavaScript snippet that works everywhere.

The ai4shops.com installation script is a lightweight JavaScript snippet that brings your forms, modals, and chatbot to life on your website. 🚀

The Basic Script

Here's what it looks like:

<script
  src="https://ai4shops.com/embed.js"
  data-project-id="proj_your_unique_id"
  data-api-key="your_api_key"
></script>

That's it! This one script loads everything for your project.

Where to Add It

Best Practice: Before </body>

Place the script just before the closing </body> tag in your HTML:

<!DOCTYPE html>
<html>
  <head>
    <title>My Website</title>
  </head>
  <body>
    <!-- Your website content -->
 
    <!-- ai4shops.com Script -->
    <script
      src="https://ai4shops.com/embed.js"
      data-project-id="proj_abc123"
      data-api-key="sk_live_xyz789"
    ></script>
  </body>
</html>

Why before </body>?

  • Page content loads first (faster perceived speed)
  • Ensures DOM is ready
  • Better SEO
  • Industry standard

Alternative: In <head> with Async

For advanced users:

<head>
  <script
    async
    src="https://ai4shops.com/embed.js"
    data-project-id="proj_abc123"
  ></script>
</head>

The async attribute ensures it doesn't block page rendering.

Installation Methods

Install once, works for all forms/modals/chatbots in that project:

<script
  src="https://ai4shops.com/embed.js"
  data-project-id="proj_abc123"
></script>

Loads:

  • All active forms
  • All active modals (with correct triggers)
  • Your chatbot (if configured)

Best for:

  • Most websites
  • Consistent experience
  • Easy management

Method 2: Specific Widget

Load only specific widgets:

Single Form:

<script src="https://ai4shops.com/embed.js" data-form-id="form_xyz789"></script>

Single Modal:

<script
  src="https://ai4shops.com/embed.js"
  data-modal-id="modal_abc456"
></script>

Chatbot Only:

<script
  src="https://ai4shops.com/embed.js"
  data-chatbot-id="chat_def123"
></script>

Best for:

  • Landing pages (one specific form)
  • A/B testing
  • Selective deployment

Method 3: Multiple Widgets

Mix and match:

<script
  src="https://ai4shops.com/embed.js"
  data-project-id="proj_abc123"
  data-form-id="form_xyz789"
  data-modal-id="modal_abc456"
  data-chatbot-enabled="true"
></script>

Configuration Options

Customize behavior with data attributes:

Display Options

<script
  src="https://ai4shops.com/embed.js"
  data-project-id="proj_abc123"
  data-theme="auto"
  data-position="bottom-right"
  data-language="en"
></script>

Available Options:

data-theme

  • light: Light mode colors
  • dark: Dark mode colors
  • auto: Matches system preference (default)

data-position (for chatbot)

  • bottom-right (default)
  • bottom-left
  • top-right
  • top-left

data-language

  • en: English (default)
  • es: Spanish
  • fr: French
  • de: German
  • it: Italian
  • pt: Portuguese
  • ... (50+ languages)

Performance Options

<script
  src="https://ai4shops.com/embed.js"
  data-project-id="proj_abc123"
  data-lazy-load="true"
  data-preload="false"
></script>

data-lazy-load

  • true: Load when widget becomes visible
  • false: Load immediately (default)

data-preload

  • true: Preload resources (faster widget display)
  • false: Load on-demand (default)

Privacy Options

<script
  src="https://ai4shops.com/embed.js"
  data-project-id="proj_abc123"
  data-cookie-consent="required"
  data-gdpr-mode="true"
></script>

data-cookie-consent

  • required: Wait for consent before loading
  • optional: Load immediately (default)

data-gdpr-mode

  • true: Enhanced privacy mode
  • false: Standard mode (default)

Platform-Specific Installation

WordPress

Option 1: Header/Footer Plugin

  1. Install "Insert Headers and Footers" plugin
  2. Paste script in footer section
  3. Save

Option 2: Theme Editor

  1. Appearance → Theme Editor
  2. Open footer.php
  3. Find </body> tag
  4. Paste script above it
  5. Update file

Option 3: Custom HTML Widget

  1. Appearance → Widgets
  2. Add "Custom HTML" widget to footer
  3. Paste script
  4. Save

Detailed WordPress guide →

Shopify

  1. Online Store → Themes
  2. Click "..." → Edit Code
  3. Open theme.liquid
  4. Find </body> (usually near bottom)
  5. Paste script above it
  6. Save

Detailed Shopify guide →

Custom HTML

Direct edit of your HTML files:

  1. Open HTML file in editor
  2. Find </body> tag
  3. Paste script above it
  4. Save and upload

Detailed custom site guide →

Verifying Installation

Add the Script

Install using one of the methods above.

Visit Your Website

Open your site in a browser (use incognito/private mode for clean test).

Open Developer Console

  • Chrome/Edge: Press F12 or Ctrl+Shift+I (Windows) / Cmd+Option+I (Mac)
  • Firefox: Press F12 or Ctrl+Shift+K (Windows) / Cmd+Option+K (Mac)
  • Safari: Enable Developer Menu → Develop → Show JavaScript Console

Check Console Messages

Look for:

✓ ai4shops.com v2.1.0 loaded successfully
✓ Project: proj_abc123
✓ Widgets: 2 forms, 1 modal, 1 chatbot

If you see errors, see Troubleshooting below.

Test Widgets

  • Forms: Should display on page
  • Modals: Should trigger based on settings
  • Chatbot: Chat bubble should appear

Troubleshooting

Script Not Loading

Error: "Failed to load resource"

Possible causes:

  • Typo in URL
  • Internet connection issue
  • Firewall/ad blocker
  • Server issue (check status.ai4shops.com)

Solution:

  • Verify URL is exactly: https://ai4shops.com/embed.js
  • Check browser console for details
  • Try different browser
  • Contact support if persistent

Invalid API Key

Error: "Authentication failed: Invalid API key"

Solution:

  • Copy API key from dashboard (Settings → API Keys)
  • Make sure you copied the entire key
  • Regenerate if compromised
  • Update script with new key

Widgets Not Showing

Forms not appearing:

  • Check if form is set to "Active" in dashboard
  • Verify data-form-id is correct
  • Look for CSS conflicts (use browser inspector)
  • Check if form has display conditions

Modals not triggering:

  • Check trigger settings (exit intent, scroll, time delay)
  • Verify modal is "Published"
  • May need to wait for trigger condition
  • Test with "On page load" trigger

Chatbot not visible:

  • Ensure chatbot is "Published" in settings
  • Check position (might be off-screen)
  • Look for CSS z-index conflicts
  • Verify training data exists

Performance Issues

Page loading slowly:

Most likely NOT ai4shops.com (script is only ~40KB compressed).

Check:

  • Other scripts/plugins (some are 1MB+)
  • Large images
  • Server response time
  • Use tools: Google PageSpeed Insights

Optimize ai4shops.com:

<script
  async
  defer
  src="https://ai4shops.com/embed.js"
  data-project-id="proj_abc123"
  data-lazy-load="true"
></script>

CORS Errors

Error: "Cross-Origin Request Blocked"

Solution:

  1. Go to Project Settings → Security
  2. Add your domain to "Allowed Origins"
  3. Save changes
  4. Clear cache and test

Security Best Practices

Keep API Keys Secure

DO:

  • ✅ Use in public website HTML (it's safe - domain restricted)
  • ✅ Regenerate if compromised
  • ✅ Set allowed domains

DON'T:

  • ❌ Share in public repositories (use environment variables)
  • ❌ Use same key across multiple projects
  • ❌ Include in public documentation

Domain Restrictions

Lock down your widgets:

  1. Settings → Security → Allowed Domains
  2. Add your domains:
    https://example.com
    https://www.example.com
    https://shop.example.com
    
  3. Widgets only work on listed domains

Pro Tip: Add both www and non-www versions of your domain!

Content Security Policy (CSP)

If your site uses CSP headers, add:

Content-Security-Policy:
  script-src 'self' https://ai4shops.com;
  connect-src 'self' https://api.ai4shops.com;
  frame-src 'self' https://ai4shops.com;

Advanced Usage

Programmatic Control

Control widgets with JavaScript:

Show/Hide Chatbot:

// Hide chatbot
window.AI4Shops.chatbot.hide();
 
// Show chatbot
window.AI4Shops.chatbot.show();
 
// Toggle
window.AI4Shops.chatbot.toggle();

Open/Close Modal:

// Open specific modal
window.AI4Shops.modal.open("modal_abc123");
 
// Close all modals
window.AI4Shops.modal.close();

Trigger Form:

// Open form in modal
window.AI4Shops.form.openModal("form_xyz789");

Event Listeners

React to widget events:

// Listen for form submissions
window.addEventListener("ai4shops:form:submitted", (event) => {
  console.log("Form submitted:", event.detail);
  // Send to analytics, show thank you, etc.
});
 
// Listen for chat messages
window.addEventListener("ai4shops:chat:message", (event) => {
  console.log("Chat message:", event.detail);
});
 
// Listen for modal views
window.addEventListener("ai4shops:modal:viewed", (event) => {
  console.log("Modal viewed:", event.detail);
});

Custom Styling

Override default styles:

/* Customize chatbot button */
.ai4shops-chatbot-button {
  background-color: #ff6b6b !important;
  border-radius: 50% !important;
}
 
/* Customize form inputs */
.ai4shops-form-input {
  border: 2px solid #4ecdc4 !important;
  border-radius: 8px !important;
}
 
/* Customize modal */
.ai4shops-modal-overlay {
  background-color: rgba(0, 0, 0, 0.8) !important;
}

Use !important to override default styles. Future updates may change class names.

Next Steps

WordPress Integration

Step-by-step WordPress guide

View

Shopify Integration Complete Shopify installation

View

Create Your First Form Build a form to embed

View

Set Up Chatbot

Train and deploy AI chat

View

Installation is simple, but powerful! Now make your website interactive! 🚀✨