Skip to main content

Installation

# using npm
npm install @metrifox/angular-sdk

# or pnpm
pnpm add @metrifox/angular-sdk

# or yarn
yarn add @metrifox/angular-sdk

Setup

1. Register Providers

Add provideMetrifox() to your application configuration (usually in app.config.ts for standalone applications).
import { ApplicationConfig } from '@angular/core';
import { provideMetrifox } from '@metrifox/angular-sdk';

export const appConfig: ApplicationConfig = {
  providers: [
    provideMetrifox(),
  ],
};

2. Initialize the SDK

Initialize the SDK once with your client key, typically in your root component (e.g., AppComponent).
import { Component, OnInit } from '@angular/core';
import { MetrifoxService } from '@metrifox/angular-sdk';

@Component({ ... })
export class AppComponent implements OnInit {
  ngOnInit() {
    MetrifoxService.initialize({
      clientKey: "your-client-key",
    });
  }
}
Works with Angular 16+ (Standalone Components supported).

Widgets

CustomerPortal

Displays a customizable customer dashboard with plans, subscriptions, billing, credits, and more. Import CustomerPortalComponent in your component:
import { CustomerPortalComponent } from '@metrifox/angular-sdk';

@Component({
  selector: 'app-my-portal',
  standalone: true,
  imports: [CustomerPortalComponent],
  template: `
    <metrifox-customer-portal
      [customerKey]="'your-customer-key'"
      [sectionsConfig]="sectionsConfig"
    ></metrifox-customer-portal>
  `
})
export class MyPortalComponent {
  sectionsConfig = [
    { key: "subscription" },
    { key: "billingHistory", hidden: true },
  ];
}

Section Configuration

The sectionsConfig input controls what appears in the portal.
PropertyTypeDescription
keySectionKeyUnique key of the section (see list below)
hiddenbooleanHide this section when true

Built-in Section Keys

KeyDescription
upcomingInvoiceDisplays next invoice details
subscriptionActive subscription overview
walletBalanceShows user wallet balance
entitlementUsageDisplays resource usage
paymentOverviewPayment summary and methods
billingHistoryList of past transactions
planCurrent plan details

Pricing Table

Displays subscription plans and one-time purchases in a configurable pricing table component. Import PricingTableComponent in your component:
import { PricingTableComponent } from '@metrifox/angular-sdk';

@Component({
  selector: 'app-pricing',
  standalone: true,
  imports: [PricingTableComponent],
  template: `
    <metrifox-pricing-table
      [checkoutUsername]="'your-checkout-username'"
      [productKey]="'your-product-key'"
    ></metrifox-pricing-table>
  `
})
export class PricingPageComponent {}

Inputs

The inputs control how the pricing table is configured.
InputTypeRequiredDefaultDescription
checkoutUsernamestringYesUnique username used for checkout. This can be found in Settings → Checkout.
productKeystringYesUnique product identifier. This can be found on the product page.
plansOnlybooleanNofalseControls whether only subscription plans are rendered.
singlePurchasesOnlybooleanNofalseControls whether only single purchases are rendered.
showTabHeaderbooleanNotrueControls whether the tab header for switching between offerings is rendered.
If both plansOnly and singlePurchasesOnly are false or undefined, both plans and single purchases are displayed.

Styling

Import the SDK’s global styles into your global styles file (e.g., src/styles.css):
@import "@metrifox/angular-sdk/styles.css";
This is required for proper styling of all widgets.

Theming

The SDK accepts an optional theme object during initialization to match your brand styles.
MetrifoxService.initialize({
  clientKey: "your-client-key",
  theme: {
    customerPortal: {
        // ... theme configuration
    }
  }
});
You can also update the theme dynamically:
MetrifoxService.updateTheme({
  customerPortal: {
    section: { background: "#000000" }
  }
});
See the React SDK documentation for the full list of theme properties, as the theme object structure is identical.