A complete guide for integrating Joy Subscription into your headless storefront to enable subscription features on your store.
Introduction
If you're using a headless storefront instead of Shopify's default theme, you'll need to integrate the Joy Subscription SDK to enable subscription features on your store.
This guide uses Next.js (App Router) for code examples, but the SDK works with any JavaScript framework. Adapt the code patterns to your specific framework as needed.
Products with selling plans configured in Shopify Admin
A headless storefront built with a JavaScript framework (Next.js, Gatsby, Nuxt, Remix, etc.)
Storefront API access token from Shopify Admin
Node.js version 18 or higher
Get Your Storefront API Access Token
Go to Shopify Admin → Settings → Apps and sales channels
Click Develop apps → Create an app
Name your app (e.g., "Headless Storefront")
Go to Configuration → Storefront API → Select required permissions
Click Install app and copy the Storefront API access token
Install the SDK
Run the following command in your project directory:
Or if you're using npm/yarn:
Part 2: Basic Configuration
2.1. Environment Variables
Create a .env.local file (or equivalent for your framework) at your project root:
Important: The SDK runs on the client side and needs access to your Shopify domain and Storefront token. Make sure these variables are exposed to the browser (in Next.js, use the NEXT_PUBLIC_ prefix; other frameworks may have different conventions).
2.2. TypeScript Declarations
The SDK doesn't include TypeScript definitions. Create a declaration file to avoid type errors:
Create file: types/joy-subscription-sdk.d.ts
Part 3: Product Subscription Widget
The widget allows customers to select subscription plans directly on the product page.
3.1. Create Subscription Context
This context shares state between the Widget, Add to Cart button, and Variant Selector.
Important: You must pass shopDomain and storefrontAccessToken directly to the constructor. Standalone bundles (joy-subscription-sdk/widget, etc.) do not read config from SubscriptionSDK.configure().
3.3. Add Widget to Product Page
Wrap your product description with SubscriptionProvider and place the widget:
Create a subscription plan (e.g., "Monthly Subscription - Every 1 month")
Assign the selling plan to your products
8.2. Verify Product Has Selling Plan
Go to Products → Select a product → Check the Purchase options section. You should see your selling plan listed.
8.3. Redirect from Shopify Theme (Optional)
If customers might land on your Shopify theme (e.g., after checkout), you can redirect them to your headless storefront:
Go to Online Store → Themes → Edit code
Open layout/theme.liquid
Add the following code right after <link rel="preconnect" ...>:
Replace your-headless-store-domain.com with your actual headless storefront domain.
8.4. Customer Account (Optional)
If you want to use Shopify's New Customer Accounts:
Part 9: Deployment
9.1. Environment Variables
Before deploying, ensure all required environment variables are configured in your hosting platform:
Variable
Required
Description
SHOPIFY_STORE_DOMAIN
Yes
Your Shopify store domain
SHOPIFY_STOREFRONT_ACCESS_TOKEN
Yes
Storefront API token (server-side)
NEXT_PUBLIC_SHOPIFY_DOMAIN
Yes (SDK)
Your Shopify store domain (client-side)
NEXT_PUBLIC_STOREFRONT_TOKEN
Yes (SDK)
Storefront API token (client-side)
Important: Client-side environment variables (like NEXT_PUBLIC_* in Next.js) are typically injected at build time. If you add or change them after deployment, you'll need to rebuild and redeploy for changes to take effect. Refer to your hosting platform's documentation for specific instructions.
9.2. Build and Deploy
Build your project and deploy to your hosting platform of choice. Common options include:
Vercel — Optimized for Next.js
Netlify — Supports multiple frameworks
AWS Amplify — Full-stack deployment
Cloudflare Pages — Edge-first deployment
Self-hosted — Any Node.js-capable server
Follow your hosting platform's deployment guide for specific instructions.
9.3. Verify After Deployment
After deployment, verify the integration is working:
Visit a product page → Subscription widget should appear
Select a plan → Button changes to "Subscribe"
Click "Subscribe" → Item is added to cart with selling plan
npm install joy-subscription-sdk
# or
yarn add joy-subscription-sdk
# Store info
COMPANY_NAME="Your Store Name"
SITE_NAME="Your Site Name"
# Shopify credentials (server-side)
SHOPIFY_STORE_DOMAIN="your-store.myshopify.com"
SHOPIFY_STOREFRONT_ACCESS_TOKEN="your-storefront-access-token"
# Shopify credentials (client-side - used by SDK)
NEXT_PUBLIC_SHOPIFY_DOMAIN="your-store.myshopify.com"
NEXT_PUBLIC_STOREFRONT_TOKEN="your-storefront-access-token"