Skip to main content
This page documents @commerce-blocks/sdk v3 (3.x). For v2 integrations, see Upgrade to v3.
App embed installed? Then the theme only renders. On a Shopify theme with the Layers app embed enabled, the embed’s Storefront Pixel wraps every Layers request the SDK makes. It owns:
  • Identity: device, session, and customer IDs. Leave identity unset in createSDK().
  • Context: market, locale, currency, cart, purchase history, customer profile, and marketing parameters. Don’t hand-build these. See Context for the few fields a theme still sends.
  • Semantic redirects: the pixel follows _meta.redirect from search and autocomplete responses. Don’t navigate on it in theme code.
  • Block deduplication: the pixel sets excludeProductIds on every Blocks request to the products already on the page. Any excludeProductIds you send is replaced.
  • Attribution and tracking: product, block, banner, and search events, and the _layers_attribution add-to-cart property.
Your theme passes the tokens from #layers-config, calls the SDK with the request inputs (collection, query, filters, sort, page), and renders the results. The identity and context examples in these pages are for headless storefronts that don’t load the embed.
The Layers SDK (@commerce-blocks/sdk) is an ES module SDK for product discovery powered by the Layers API. It provides reactive state management, built-in caching, and a unified interface for browse, search, recommendations, and image search.

Key features

Layers API integration

Full access to Layers’ search, browse, recommendations, blocks, and image search APIs with built-in error handling.

Reactive state management

Framework-agnostic reactive controllers with subscribe() for automatic UI updates and in-flight request deduplication.

Product card controller

Reactive product card management with variant selection, availability logic, and automatic state updates.

Extensibility

Transform products, collections, search, blocks, and other responses with custom transforms. Build filters with a type-safe DSL.

Quick start

SDK methods

The SDK returns controllers for all Layers storefront APIs:

Architecture

The SDK uses a controller pattern where each method returns a controller with reactive state and a get() method. All controllers support two ways to consume state:

Next steps

Installation

Learn how to install and configure the SDK in your project.

API reference

Explore the complete API reference for all SDK methods.

Framework integration

Patterns for React, Vue, Svelte, Lit, Alpine.js, and vanilla JS.

Error handling

Learn how to handle errors gracefully with the Result pattern.