Skip to Content
Headless SDKCLI Reference

CLI Reference

The AppFunnel CLI lets you scaffold, develop, build, and publish headless funnels from the command line.

Installation

npm install -g appfunnel

Commands

appfunnel login

Authenticate via browser OAuth. Opens your default browser to authorize. Times out after 2 minutes if not completed.

appfunnel login

appfunnel whoami

Display current auth status including email, user ID, and token expiration.

appfunnel whoami

appfunnel init

Scaffold a new funnel project.

appfunnel init

Interactive prompts:

  1. Select a project from your account
  2. Select a template
  3. Optionally configure products — select a store, choose a price, and set trial settings (3, 7, 14, 30, or 90 day options)

appfunnel dev

Start a Vite dev server with hot module replacement.

appfunnel dev appfunnel dev -p 3000

Options:

FlagDescriptionDefault
-p, --port <n>Port number5173

Behavior:

  • Real product prices are fetched from the API
  • Tracking events are mocked and logged to the console
  • Watches src/pages/ for file changes and triggers reload
  • Watches appfunnel.config.ts for changes and triggers reload
  • Auto-prompts for projectId if missing from config

appfunnel build

Create a production build.

appfunnel build

Validation checks:

  • CLI and SDK major.minor versions must match
  • All route targets must reference existing pages
  • All condition variables must be declared in config
  • System variables (page.*, device.*, etc.) are always valid

Output:

The build outputs to dist/ containing manifest.json, JS chunks, CSS, and assets.

Size limits:

  • 2MB total bundle size (warning)
  • 500KB per JS file (warning)

Built-in query params are always included and do not need to be declared:

utm_source, utm_medium, utm_campaign, utm_content, utm_term

appfunnel publish

Deploy to AppFunnel hosting.

appfunnel publish

Requires dist/manifest.json — run appfunnel build first.

The first publish creates a new headless funnel and writes the funnelId back to your config. Subsequent publishes update the existing funnel.

Error Codes

CodeDescriptionFix
AUTH_REQUIREDNot logged inRun appfunnel login
AUTH_EXPIREDToken expiredRun appfunnel login
CONFIG_NOT_FOUNDNo appfunnel.config.tsRun appfunnel init or cd to project
INVALID_ROUTERoute target doesn’t existCheck to value matches a page filename
UNDEFINED_VARIABLEUndeclared variable in conditionAdd to responses, data, or queryParams in config
VERSION_MISMATCHCLI/SDK version incompatibleRun npm install @appfunnel-dev/sdk@latest
BUILD_NOT_FOUNDNo dist/ directoryRun appfunnel build first
FUNNEL_NOT_HEADLESSTarget funnel is wrong typeCreate new headless funnel or remove funnelId
BUNDLE_TOO_LARGETotal bundle exceeds 2MBReduce dependencies, optimize assets
PAGE_SIZEJS file exceeds 500KBSplit code, reduce dependencies
INVALID_PAGEPage file has errorsCheck definePage() syntax
NO_PAGESNo .tsx files in src/pages/Create at least one page
NO_PROJECTSNo projects in accountCreate a project in the dashboard
MISSING_PROJECT_IDConfig missing projectIdSet in config or run appfunnel dev
MISSING_INITIAL_PAGE_KEYMissing initialPageKey in appfunnel.config.ts.Set in config
API_ERRORBackend request failedCheck network and auth
PUBLISH_FAILEDPublish request failedCheck build output and retry

window.appfunnel External API

A global API available at window.appfunnel for third-party script integration (e.g., GTM custom HTML tags).

Variables

// Read a single variable window.appfunnel.getVariable('email') // Write a variable window.appfunnel.setVariable('email', 'user@example.com') // Read all variables window.appfunnel.getVariables()
MethodDescription
getVariable(id)Read a variable by ID
setVariable(id, value)Write a variable value
getVariables()Read all variables as an object
window.appfunnel.getCurrentPageId() window.appfunnel.goToNextPage() window.appfunnel.goBack()
MethodDescription
getCurrentPageId()Returns the current page key
goToNextPage()Navigate forward
goBack()Navigate back

Products

window.appfunnel.selectProduct('price_abc123')
MethodDescription
selectProduct(id)Select a product by ID

Payments

window.appfunnel.getCustomerId() window.appfunnel.isPaymentAuthorized()
MethodDescription
getCustomerId()Returns the payment customer ID
isPaymentAuthorized()Returns whether payment has been authorized

Events

// Subscribe to an event window.appfunnel.on('page_view', (data) => { console.log(data) }) // Unsubscribe window.appfunnel.off('page_view', callback) // Emit a custom event window.appfunnel.callEvent('custom_action', { key: 'value' })
MethodDescription
on(type, callback)Subscribe to events
off(type, callback)Unsubscribe from events
callEvent(name, data?)Emit a custom event

Misc

window.appfunnel.openUrl('https://example.com')
MethodDescription
openUrl(url)Open a URL
Last updated on