ShopGPT SDK for shoppable TV ads

Add a buy button to Connected TV ads with the shopgpt npm package, and update the TV live when a viewer adds to cart.

What it does

ShopGPT is RankUp's AI shopping experience. A shopper opens a product in ShopGPT, asks questions about it in a chat, and adds it to their cart.

The ShopGPT SDK brings that to Connected TV. When a shoppable ad plays, your TV app shows a buy button. The viewer presses it with the remote, the product is added to their cart, and the TV updates live to show the sale.

The SDK is the shopgpt package on npm. It runs in any HTML5 TV app, including Samsung Tizen, LG webOS, Fire TV and Android TV. It needs no native code.

How it works

  1. The ad starts. Your player reads three values from the VAST ad and passes them to the SDK.
  2. The SDK creates a session. RankUp looks up the product from its ID and returns its title, image and price.
  3. Your app shows the button. Use the built-in button or draw your own.
  4. The viewer presses it. The SDK marks the product as added to cart.
  5. The TV updates. The SDK polls the session and tells your app when it converts.

Each session also carries a link that opens the same product in ShopGPT on a phone, so a viewer can continue there.

Before you start

  • A TV app or web player that runs HTML5 and JavaScript.
  • Ads that carry a RankUp product ID. RankUp provides the ID for each product you advertise.
  • React 18 or later, only if you use the React components.

Install

npm install shopgpt

The package ships as ES modules with TypeScript types. React is an optional peer dependency.

Quickstart

import { ShopGPTCTV } from "shopgpt";

const ctv = new ShopGPTCTV({ apiBase: "https://app.rankup.diy" });

// Listen for conversions
ctv.onEvent((event) => {
  if (event.type === "added_to_cart") showBadge(event.session);
});

// When the ad starts, pass the three VAST values as they are
const { session } = await ctv.createSession({ shoppable, rankupid, cta });
if (!session) return; // not a shoppable ad: play it as a normal ad

// Keep the TV in sync with the session
ctv.pollSession(session.id);

// When the viewer presses the button
await ctv.addToCart(session.id);

The ad parameters

A shoppable ad carries three values. Pass them to createSession unchanged.

ParameterTypeDescription
shoppablebooleanSet to false for a normal ad. No session is created
rankupidnumber or stringThe RankUp product ID. Required
ctastringThe button label for this ad, for example "Scan to buy"

You never send product details. RankUp resolves the title, image and price from rankupid.

Use it with React

Import the React bindings from shopgpt/react.

Drop-in player

ShopGPTCTVPlayer plays the video, creates the session and shows the button.

import { ShopGPTCTVPlayer } from "shopgpt/react";

<ShopGPTCTVPlayer
  videoSrc="https://example.com/ad.mp4"
  ad={{ shoppable: true, rankupid: 10403886137619, cta: "Scan to buy" }}
  cta="send_to_phone"
  onConverted={(session) => console.log("sold", session.cartCount)}
/>;
PropDescription
videoSrcURL of the ad video
adThe three ad parameters
apiBaseRankUp API base URL
ctaButton preset: add_to_cart (default) or send_to_phone
ctaLabelCustom button text. Overrides the preset and the ad's cta
onConvertedCalled with the session when the viewer adds to cart

Your own player

Use the hook with your existing player, and place the button where you want it.

import { ShopGPTAddToCartButton, useShopGPTShoppableAd } from "shopgpt/react";

function AdOverlay({ ad }) {
  const { session, loading } = useShopGPTShoppableAd(ad, {
    apiBase: "https://app.rankup.diy",
  });

  if (loading || !session) return null;

  return (
    <div className="overlay">
      <p>{session.product.title}</p>
      <ShopGPTAddToCartButton session={session} label="Buy Now" />
    </div>
  );
}
HookWhat it does
useShopGPTShoppableAd(ad, options)Creates the session when the ad starts and keeps it up to date. Returns session, loading and create
useShopGPTSession(sessionId, apiBase)Follows an existing session. Returns session and error

Pass autoCreate: false in the options to create the session yourself by calling create().

Customize the button

ShopGPTAddToCartButton has two presets and accepts any custom text or styling.

// Preset labels
<ShopGPTAddToCartButton session={session} cta="add_to_cart" />
<ShopGPTAddToCartButton session={session} cta="send_to_phone" />

// Custom text, styling and a callback
<ShopGPTAddToCartButton
  session={session}
  label="Buy Now"
  className="my-cta"
  onCta={(session) => analytics.track("ctv_cta", { sessionId: session.id })}
/>
PropDescription
sessionThe session from the hook. The button renders nothing without one
ctaadd_to_cart shows "Add to Cart". send_to_phone shows "Send to Phone"
labelCustom text. Overrides the preset
qtyQuantity to add. Defaults to 1
classNameReplaces the default styling
onAddedCalled when the product is added
onCtaCalled after a successful press

After a successful press, the button is replaced by an "Added to cart" confirmation.

Client reference

Create one ShopGPTCTV client and reuse it.

const ctv = new ShopGPTCTV({
  apiBase: "https://app.rankup.diy",
  pollIntervalMs: 2500,
});
OptionDefaultDescription
apiBaseThe page's own originRankUp API base URL. Set this in a TV app
pollIntervalMs2500How often pollSession checks the session
fetchImplGlobal fetchA custom fetch, for platforms without one
MethodDescription
createSession(ad)Creates a session from the ad parameters. Returns { session, mobileUrl }. session is null for a non-shoppable ad
getSession(id)Fetches a session once
pollSession(id, onUpdate)Checks the session on an interval and emits events when its status changes. Returns a function that stops polling
stopPolling()Stops the current poll
addToCart(id, { qty })Adds the product to the cart and marks the session converted
markScanned(id)Marks the session as opened on a phone
onEvent(listener)Subscribes to events. Returns a function that unsubscribes

Events

EventWhen
session_createdA session was created
session_updatedThe session's status changed
scannedThe viewer opened the product on a phone
added_to_cartThe viewer added the product to their cart

Every event carries the current session.

The session object

{
  "id": "session-id",
  "status": "created",
  "product": {
    "id": "product-id",
    "title": "Product title",
    "brand": "Brand",
    "price": "999 INR",
    "imageUrl": "https://example.com/image.jpg"
  },
  "cta": "Scan to buy",
  "mobileUrl": "https://shopgpt.rankup.diy/?product_id=...&ctv=...",
  "cartCount": 0,
  "scanCount": 0,
  "createdAt": "2026-01-01T00:00:00.000Z",
  "updatedAt": "2026-01-01T00:00:00.000Z"
}

A session moves through these statuses:

StatusMeaning
createdThe ad is playing and the button is showing
scanned, viewingThe viewer opened the product on a phone
added_to_cartThe viewer added the product to their cart
completedThe purchase flow finished
expiredThe session ran out of time

A session lasts 10 minutes, which covers one ad spot. Create a new session each time an ad starts.

Continue on a phone

session.mobileUrl opens the product in ShopGPT, where the viewer can chat about it and add it to their cart. To offer this, show the link as a QR code on screen.

When the viewer opens the link or adds to cart on their phone, ShopGPT reports it back to the session. Your TV app receives the scanned and added_to_cart events through pollSession, the same way as a remote press.

REST API

The SDK is a thin wrapper over these endpoints. Call them directly if you cannot use the package. They accept cross-origin requests.

MethodPathPurpose
POST/api/ctv/sessionCreate a session from { shoppable, rankupid, cta }
GET/api/ctv/session/{id}Read a session
PATCH/api/ctv/session/{id}Set status to scanned, viewing or completed
POST/api/ctv/cartAdd to cart with { sessionId, qty }
GET/api/ctv/cart?sessionId={id}List the cart items for a session

Troubleshooting

ProblemWhat to do
createSession failed: 404No product matches that rankupid. Check the ID in the ad
createSession failed: 400The ad did not include a rankupid
session is nullThe ad has shoppable: false. Play it as a normal ad
getSession failed: 404The session expired or the ID is wrong. Create a new session
The TV does not update after a pressCall pollSession(session.id), or use useShopGPTShoppableAd, which polls for you
Requests go to the wrong hostSet apiBase when you create the client. Without it, the SDK uses the page's own origin

Last updated

Ready to set this up?

Open RankUp and follow these steps in your own project.