Set up the Shop SDK
The Shop SDK is a JavaScript library for integrating Shop functionality into any storefront. Load a single script from Shopify's CDN, initialize the SDK with your configuration, then create feature instances programmatically.
The Shop platform is in early access. Features and APIs may change before general availability.
The Shop platform is in early access. Features and APIs may change before general availability.
Anchor to Step 1: Load and initialize the SDKStep 1: Load and initialize the SDK
Add the SDK loader script to your page and call initialize with your configuration. The apiKey is the client ID from your Dev Dashboard app.
HTML
The script registers window.ShopSDK when it loads. initialize returns an SDK instance that you use to create features.
Anchor to Step 2: Create a feature instanceStep 2: Create a feature instance
Call sdk.create() with a feature name and configuration. The method returns a Promise that resolves once the feature's code has loaded.
JavaScript
The SDK creates the underlying HTML element for you. You're responsible for inserting instance.element into the DOM wherever you want it to appear.
Anchor to ConfigurationConfiguration
Anchor to [object Object], optionsinitialize options
initialize options| Option | Type | Description |
|---|---|---|
apiKey | string | Your client ID from the Dev Dashboard. |
appearance | object | Styling overrides. See Appearance. |
features | object | Eagerly preload feature scripts. For example, { 'lead-capture': true } starts loading the lead capture code immediately. |
locale | string | BCP-47 locale tag (for example, 'en', 'fr', 'ro-RO'). Defaults to 'en'. |
onError | function | SDK-level error handler. See Event handlers. |
onReady | function | Fires when a feature instance finishes loading. See Event handlers. |
onRecognized | function | Fires when a Shop user is detected (or not). See Event handlers. |
scope | string | Space-separated list of OAuth scopes to request. |
Anchor to AppearanceAppearance
Control the look of SDK components with CSS custom properties:
JavaScript
| Variable | Description |
|---|---|
--buttons-radius | Border radius for buttons. |
--font-paragraph--size | Font size for paragraph text. |
--font-paragraph--line-height | Line height for paragraph text. |
--x-spacing-base | Base spacing unit. |
Anchor to Event handlersEvent handlers
SDK-level event handlers fire for all feature instances. Pass them as top-level properties on the initialize config:
JavaScript
| Handler | Payload | Description |
|---|---|---|
onReady | { elementTagName, detail } | Fires when a feature instance finishes loading. |
onRecognized | { recognized } | Fires when a Shop user is detected (or not) in the current session. |
onError | { message, cause, feature } | Fires when an error occurs in any feature instance. |
Anchor to Updating and destroyingUpdating and destroying
Call sdk.update() to merge new configuration into the SDK instance:
JavaScript
Call sdk.destroy() to tear down all feature instances and clean up event listeners. You can also destroy individual feature instances with instance.destroy().
Anchor to Next stepsNext steps
- See the full Shop SDK reference for all configuration options and feature APIs.
- Use the lead capture feature to collect email addresses from Shop users on your storefront.
- Use
onRecognizedto silently detect returning Shop users.