Sweet Spot API

Command Palette

Search for a command to run...

Widget SDK

The Sweet Spot Widget SDK allows you to embed lease pricing information directly on your product pages. When customers view a product, they can instantly see available lease terms and monthly payment options.

Quick Start

Add the following code to your product page:

HTML
<div id="sweetspot-widget"></div>

<script>
  window._sweetspot_config = {
    public_api_key: "your_api_key",
    sku: "your_product_variant_id"
  };
</script>
<script src="https://widget.thesweetspot.com/widget.js"></script>

That's it! The widget will automatically display lease options for the specified product.

Installation

CDN (Recommended)

Include the widget script from our CDN:

<script src="https://widget.thesweetspot.com/widget.js"></script>

Staging Environment

For testing, use the staging CDN:

<script src="https://staging.widget.thesweetspot.com/widget.js"></script>

Configuration

Configure the widget by setting window._sweetspot_config before loading the script.

Configuration Options

OptionTypeRequiredDefaultDescription
public_api_keystringYes-Your Sweet Spot public API key
skustringYes-Product variant ID (e.g., pvar_abc123)
environmentstringNo"production"API environment: "staging" or "production"
containerstringNo"#sweetspot-widget"CSS selector for widget container
showWhyLeasebooleanNotrueShow "Why Lease?" information in modal
showDisclaimerbooleanNotrueShow disclaimer text in modal
theme'light' | 'dark'No'light'Widget color theme for light or dark backgrounds
compactbooleanNofalseEnable compact display mode with minimal UI
textColorstringNo(auto based on theme)Custom text color override (CSS color value, e.g., '#333' or 'white')
accentstringNo(default brand color)Custom accent color for interactive elements
demobooleanNofalseEnable demo mode for testing without real API data
trackPageViewsbooleanNofalseEnable page view analytics tracking

Full Configuration Example

HTML
<script>
  window._sweetspot_config = {
    public_api_key: "sst_live_xxxxx",
    sku: "pvar_c9379b4d-2aae-4",
    environment: "production",
    container: "#sweetspot-widget",
    showWhyLease: true,
    showDisclaimer: true
  };
</script>

Programmatic API

For more control, you can initialize the widget programmatically using the JavaScript API.

Initialize Widget

JavaScript
window.SweetSpotWidget.init({
  public_api_key: "your_api_key",
  sku: "pvar_abc123",
  container: "#my-custom-container"
});

Multiple Widgets

You can display multiple widgets on the same page:

HTML
<div id="widget-product-1"></div>
<div id="widget-product-2"></div>

<script>
  // Initialize first widget
  window.SweetSpotWidget.init({
    public_api_key: "your_api_key",
    sku: "pvar_product_1",
    container: "#widget-product-1"
  });

  // Initialize second widget
  window.SweetSpotWidget.init({
    public_api_key: "your_api_key",
    sku: "pvar_product_2",
    container: "#widget-product-2"
  });
</script>

Destroy Widget

Remove all widget instances:

JavaScript
window.SweetSpotWidget.destroy();

API Keys

Obtaining an API Key

Contact Sweet Spot to obtain your public API key. You'll receive:

  • Production key: sst_live_xxxxx - Use in production
  • Test key: sst_test_xxxxx - Use for development and testing

Key Security

  • Public API keys are safe to include in client-side code
  • Keys are scoped to specific organizations and have read-only access
  • Never share or expose your secret API keys

Environments

EnvironmentWidget URLAPI URL
Productionhttps://widget.thesweetspot.com/widget.jshttps://api.thesweetspot.com
Staginghttps://staging.widget.thesweetspot.com/widget.jshttps://staging.api.thesweetspot.com

When using the staging widget URL, set environment: "staging" in your configuration:

HTML
<script>
  window._sweetspot_config = {
    public_api_key: "sst_test_xxxxx",
    sku: "pvar_abc123",
    environment: "staging"
  };
</script>
<script src="https://staging.widget.thesweetspot.com/widget.js"></script>

Widget Behavior

Loading State

The widget shows nothing while loading to prevent layout shifts.

No Availability

If a product doesn't have lease options available, the widget will not render anything.

Error Handling

The widget fails silently on errors to avoid disrupting your page. Check the browser console for debugging information.

This allows safe embedding on any page. If the product isn't leasable or doesn't exist, nothing is displayed.

Styling

The widget uses Shadow DOM to encapsulate its styles, ensuring:

  • Widget styles don't leak into your page
  • Your page styles don't affect the widget
  • Consistent appearance across all websites

Container Styling

You can style the container element to control widget placement:

CSS
#sweetspot-widget {
  margin-top: 16px;
  padding: 12px;
  border-top: 1px solid #eee;
}

Custom Styling

Customize the widget appearance using theme and color options:

HTML
<div id="sweetspot-widget"></div>

<script>
  window._sweetspot_config = {
    public_api_key: "your_public_api_key",
    sku: "your_product_sku",
    theme: "dark",
    textColor: "#ffffff",
    compact: true
  };
</script>

<script src="https://widget.thesweetspot.com/widget.js"></script>

Note: The dark theme uses pure white (#ffffff) text by default. The textColor option allows overriding this if needed.

Complete Example

HTML
<!DOCTYPE html>
<html>
<head>
  <title>Product Page</title>
</head>
<body>
  <div class="product">
    <h1>Premium Bike</h1>
    <p class="price">$18,999</p>

    <!-- Sweet Spot Widget -->
    <div id="sweetspot-widget"></div>
  </div>

  <script>
    window._sweetspot_config = {
      public_api_key: "sst_live_xxxxx",
      sku: "pvar_c9379b4d-2aae-4"
    };
  </script>
  <script src="https://widget.thesweetspot.com/widget.js"></script>
</body>
</html>

Troubleshooting

Widget Not Appearing

  1. Check container exists: Ensure an element with the configured selector exists in the DOM
  2. Verify API key: Confirm your API key is valid and has the correct permissions
  3. Check product variant: Ensure the product variant ID is correct and has lease options
  4. Console errors: Check the browser console for error messages

CORS Errors

The widget handles CORS automatically. If you see CORS errors, ensure you're using the correct API key for your domain.

Caching

Widget assets are cached aggressively for performance. Changes may take a few minutes to propagate after deployment.

Browser Support

The widget supports all modern browsers:

  • Chrome 60+
  • Firefox 55+
  • Safari 11+
  • Edge 79+

Need Help?

For technical support or questions, contact support@thesweetspot.com.

Widget SDK | Sweet Spot API Documentation