Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.metrifox.com/llms.txt

Use this file to discover all available pages before exploring further.

Unified theme API from v2.0.0
@metrifox/react-sdk v2.0.0 and later use one theme object on metrifoxInit({ theme }) with customerPortal and pricingTable. Root-level pricingTableTheme and the older flat / legacy theme shapes are removed and are not supported on 2.x. Releases before v2.0.0 used the previous theme model—upgrade to 2.0.0+ and migrate theme objects to the grouped structure. See SDK changelog and Styling.
Use the live playground to preview Customer Portal and Pricing Table before integrating the SDK into your application: React SDK Playground.

Installation

npm install @metrifox/react-sdk
# or
pnpm add @metrifox/react-sdk
# or
yarn add @metrifox/react-sdk

Setup

Initialize once with your client key (from the Metrifox dashboard) before rendering any SDK components.
import { metrifoxInit } from "@metrifox/react-sdk";

metrifoxInit({
  clientKey:
    process.env.NEXT_PUBLIC_METRIFOX_APP_SECRET ||
    process.env.REACT_APP_METRIFOX_APP_SECRET ||
    import.meta.env?.VITE_METRIFOX_APP_SECRET ||
    "your-client-key",
});
Works with React, Next.js, and other setups on React 18+. Environment variable names may vary by framework; use the public prefix your bundler expects so the key is available in the browser.

Widgets

CustomerPortal

Renders a customer dashboard: plans, subscriptions, billing, credits, and related sections.
import { CustomerPortal } from "@metrifox/react-sdk";

const MyCustomPlan = ({ foo }: { foo?: string }) => (
  <div>Custom plan section. Foo: {foo}</div>
);

export default function MyPortalPage() {
  return (
    <CustomerPortal
      customerKey="your-customer-key"
      sectionsConfig={[
        { key: "subscription" },
        { key: "plan", component: MyCustomPlan, props: { foo: "bar" } },
        { key: "billingHistory", hidden: true },
      ]}
      theme={{ general: { linkColor: "#2563eb" } }}
    />
  );
}
Optional theme prop: pass a CustomerPortalTheme partial to override or extend the global theme from metrifoxInit for this mount only (merged with defaults and global config).

Section configuration

PropertyTypeDescription
keySectionKeySection identifier (see table below)
hiddenbooleanWhen true, the section is not shown
componentReact.ComponentTypeReplace the default section UI
propsRecord<string, unknown>Props passed to custom or default section

Built-in section keys

KeyDescription
upcomingInvoiceNext invoice details
subscriptionActive subscription overview
creditBalanceWallet / credit balance
entitlementUsageUsage meters
paymentOverviewPayment methods and summary
billingHistoryPast invoices / transactions
planCurrent plan
Each section is wrapped in <section id="..."> for hash links (for example https://yourapp.com/billing#billing-history).
Anchor IDSection key
#upcoming-invoiceupcomingInvoice
#subscriptionsubscription
#credit-balancecreditBalance
#entitlement-usageentitlementUsage
#payment-overviewpaymentOverview
#billing-historybillingHistory
#planplan

PricingTable

Renders subscription plans and one-time purchases for a product.
import { PricingTable } from "@metrifox/react-sdk";

export default function PricingPage() {
  return (
    <PricingTable
      checkoutUsername="your-checkout-username"
      productKey="your-product-key"
      theme={{ plans: { planCards: { background: "#ffffff" } } }}
    />
  );
}

Props

PropertyTypeRequiredDefaultDescription
checkoutUsernamestringYesCheckout username from Settings → Checkout
productKeystringYesProduct identifier from the product page
plansOnlybooleanNofalseOnly subscription plans
singlePurchasesOnlybooleanNofalseOnly one-time purchases
showTabHeaderbooleanNotrueTab header for plans vs single purchases
themePricingTableThemeNoPer-instance theme override (merged with global theme.pricingTable)
If both plansOnly and singlePurchasesOnly are false or omitted, both plans and single purchases are shown.

Styling

Import global SDK styles once (for example in src/main.tsx, app/layout.tsx, or _app.tsx):
import "@metrifox/react-sdk/dist/styles.css";
This stylesheet is required for correct layout and components.

Theme configuration (supported shape)

Theming is driven by a single object passed to metrifoxInit:
metrifoxInit({
  clientKey: "...",
  theme: {
    customerPortal?: CustomerPortalTheme;
    pricingTable?: PricingTableTheme;
  },
});
Omitted keys fall back to SDK defaults. <CustomerPortal /> and <PricingTable /> may each take an optional theme prop to layer overrides for that instance only. Not supported on v2.0.0+: passing pricingTableTheme at the root of metrifoxInit, or the legacy flat customer portal / pricing table theme shapes. Those APIs are not honored in 2.x.

Customer Portal theme (CustomerPortalTheme)

Grouped by UI area; every field is optional.
GroupRole
generalPage: link color, background, radius, font, container padding
tabsTab bar: backgrounds, borders, active / inactive text
sectionsSection cards: surfaces, typography, usage bars, empty states
buttonsPrimary / secondary buttons
lineItemsSubscription line rows
tablesData tables (e.g. billing history)
modalsModal shell and actions
plansPlan cards inside the portal: currentPlanCard, planCards, planFeatures, planButton, planToggle, planTags
Minimal example:
customerPortal: {
  general: { linkColor: "#2563eb", backgroundColor: "#ffffff" },
  tabs: {
    tabBackground: "#ffffff",
    tabBorderColor: "#e5e7eb",
    activeTabBackground: "#2563eb",
    activeTabTextColor: "#ffffff",
    inactiveTabTextColor: "#6b7280",
  },
  sections: {
    background: "#ffffff",
    content: { background: "#f4f4f5", borderRadius: "8px" },
    header: { fontSize: "16px", fontWeight: "600", color: "#52525b" },
    label: { fontSize: "13px", color: "#71717a" },
    value: { fontSize: "16px", color: "#52525b" },
  },
  buttons: {
    primary: {
      backgroundColor: "#2563eb",
      border: { radius: "8px" },
      typography: { color: "#ffffff" },
    },
    secondary: {
      backgroundColor: "#e4e4e7",
      typography: { color: "#3f3f46" },
    },
  },
  plans: {
    planCards: {
      background: "#ffffff",
      border: { color: "#e5e7eb", width: "1px", radius: "8px" },
      header: { background: "#e5e7eb", textColor: "#111827" },
      description: { textColor: "#6b7280", textButtonColor: "#2563eb" },
      price: {
        amountColor: "#111827",
        primaryTextColor: "#6b7280",
        secondaryTextColor: "#9ca3af",
      },
    },
    planButton: { background: "#2563eb", textColor: "#ffffff" },
    planToggle: {
      background: "#e5e7eb",
      activeBackground: "#1f2937",
      activeText: "#ffffff",
      inactiveText: "#6b7280",
    },
  },
},

Font customization

Set customerPortal.general.fontFamily (or pricing-table-related tokens as documented in types) to any CSS font-family string. Your app must load the font (Google Fonts, @font-face, etc.) before or as the SDK mounts to avoid FOUT.

Pricing Table theme (PricingTableTheme)

Plan-related tokens live under plans (for example plans.planCards, plans.planToggle). Top-level plan keys are not supported.
KeyPurpose
plansAll plan UI: currentPlanCard, planCards, planFeatures, planButton, planToggle, planTags
tabsPlans vs single-purchase tabs: inactiveText, activeText, indicator, borderColor
checkoutBarSticky checkout bar colors
Minimal example:
pricingTable: {
  plans: {
    planCards: {
      background: "#ffffff",
      border: { color: "#e5e7eb", width: "1px", radius: "8px" },
      header: { background: "#e5e7eb", textColor: "#111827" },
      description: { textColor: "#6b7280", textButtonColor: "#2563eb" },
      price: {
        amountColor: "#111827",
        primaryTextColor: "#6b7280",
        secondaryTextColor: "#9ca3af",
      },
    },
    planButton: { background: "#2563eb", textColor: "#ffffff" },
    planToggle: {
      background: "#e5e7eb",
      activeBackground: "#1f2937",
      activeText: "#ffffff",
      inactiveText: "#6b7280",
    },
  },
  tabs: { activeText: "#2563eb", indicator: "#2563eb", borderColor: "#9ca3af" },
  checkoutBar: {
    background: "#f9fafb",
    borderColor: "#e5e7eb",
    textColor: "#3f3f46",
    buttonBackground: "#2563eb",
    buttonTextColor: "#ffffff",
  },
},
When Pricing Table is embedded in Customer Portal, plan styling follows theme.customerPortal.plans so portal and table stay consistent.

Full init example

import { metrifoxInit } from "@metrifox/react-sdk";

metrifoxInit({
  clientKey: "your-client-key",
  theme: {
    customerPortal: {
      general: { linkColor: "#2563eb", backgroundColor: "#ffffff" },
      tabs: {
        tabBackground: "#ffffff",
        activeTabBackground: "#2563eb",
        activeTabTextColor: "#ffffff",
        inactiveTabTextColor: "#6b7280",
      },
      sections: {
        background: "#ffffff",
        content: { background: "#f4f4f5", borderRadius: "8px" },
      },
      buttons: {
        primary: { backgroundColor: "#2563eb", typography: { color: "#ffffff" } },
      },
    },
    pricingTable: {
      plans: {
        planCards: {
          background: "#ffffff",
          border: { color: "#e5e7eb", radius: "8px" },
        },
        planButton: { background: "#2563eb", textColor: "#ffffff" },
      },
      tabs: { activeText: "#2563eb", indicator: "#2563eb" },
      checkoutBar: { buttonBackground: "#2563eb", buttonTextColor: "#ffffff" },
    },
  },
});
Per-widget overrides:
<CustomerPortal customerKey="..." theme={{ general: { linkColor: "#1d4ed8" } }} />
<PricingTable
  checkoutUsername="..."
  productKey="..."
  theme={{ plans: { planCards: { background: "#f8fafc" } } }}
/>

Changelog and support

Release history and breaking-change notes: SDK changelog.
Package README and issue trackers live on the public npm scope @metrifox/react-sdk.
Broader product docs: docs.metrifox.com.