> For the complete documentation index, see [llms.txt](https://docs.getpurpledot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getpurpledot.com/e-commerce-platforms/other-and-custom/use-the-browser-sdk.md). Agents can also search and read this documentation through its [MCP server](https://docs.getpurpledot.com/~gitbook/mcp).

# Use the browser SDK

Install @purple-dot/browser and initialize it with your public API key.

The package `@purple-dot/browser` loads checkout, pre-order state, and the web components. Shopify headless guides use the same package. See [Integrate with a headless storefront](https://docs.getpurpledot.com/e-commerce-platforms/shopify/integrate-with-a-headless-storefront.md).

## Before you start

* The storefront can install npm packages.
* You have the public API key from **Settings** > **Integrations**.

## Steps

1. Install the package:

```bash
npm install @purple-dot/browser
```

2. Call `init` when the storefront loads:

```js
import * as PurpleDot from '@purple-dot/browser';

PurpleDot.init({
  apiKey: 'YOUR_PUBLIC_API_KEY',
});
```

3. For combined cart, pass a cart adapter. `ShopifyAJAXCart` and `ShopifyStorefrontCart` are exported for Shopify carts. `ShopifyStorefrontCart` takes the shop domain, then the Storefront API public access token. Combined cart reads the cart from Shopify, so these adapters are for Shopify carts. On other platforms, use express checkout or the separate cart.
4. Read pre-order state and open checkout from the pages for those tasks. See [Show pre-order state on a product page](https://docs.getpurpledot.com/e-commerce-platforms/other-and-custom/show-pre-order-state-on-a-product-page.md) and [Headless setup tips](https://docs.getpurpledot.com/e-commerce-platforms/other-and-custom/headless-setup-tips.md).

`init` accepts an optional `locale` for checkout components.

## Verify

`fetchVariantsPreorderState` returns a state for a variant id on the store, or `null` when the request cannot be completed.

## Troubleshooting

* [The pre-order button is not showing](https://docs.getpurpledot.com/troubleshooting/storefront-and-checkout/pre-order-button-is-not-showing.md)

## Related

* **Concept:** [What you need to build](https://docs.getpurpledot.com/e-commerce-platforms/other-and-custom/what-you-need-to-build.md)
* **Look up:** [Use web components](https://docs.getpurpledot.com/e-commerce-platforms/other-and-custom/use-web-components.md), [Public API](https://docs.getpurpledot.com/purple-dot-apis/public-api.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.getpurpledot.com/e-commerce-platforms/other-and-custom/use-the-browser-sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
