@beamimpact/web-sdk

中文文档
1.58.4发布于 2026/11/03TypeScriptES Module近 30 天下载 1.9万

The Beam SDK enables brands to connect with their users over shared values, not transactional discounts, to build stronger loyalty. Our integration achieves this by allowing users to (a) choose a nonprofit where the brand will donate part of their purchas

原始使用文档
文档目录18 节
  1. Installation
  2. CDN
  3. NPM
  4. Using Beam
  5. Web Components
  6. React
  7. Serverside-Rendering
  8. Debug Mode
  9. Component Options
  10. beam-community impact
  11. beam-cumulative-impact
  12. beam-select-nonprofit
  13. beam-post-purchase
  14. Integrations
  15. Cart Integration
  16. Shopify
  17. Utils
  18. Integrations

@beamimpact/web-sdk

The Beam SDK enables brands to connect with their users over shared values, not transactional discounts, to build stronger loyalty. Our integration achieves this by allowing users to (a) choose a nonprofit where the brand will donate part of their purchase from a set of curated options and (b) track their cumulative impact with every order towards quantifiable goals.

Beam takes care of all the nonprofit management and compliance, impact tracking, UI styling and dynamic campaignization.

Beam

Learn more: beamimpact.com



Screenshot of Beam component

The Beam Web SDK provides a set of web components and framework-specific wrappers for integrating Beam components into an e-commerce website.

Installation

@beamimpact/web-sdk is available on NPM or via CDN.

CDN

Most e-commerce applications will load Beam over the CDN.

Include the script for the component you want to use at the top of the page:

<script
  type="module"
  crossorigin
  src="https://sdk.beamimpact.com/web-sdk/v1.36.1/dist/components/community-impact.js"
></script>

Versions

Replace v1.36.1 with the latest version available on NPM

  • type="module" is required to parse the bundle correctly
  • This script will register the Beam custom element so it can be used anywhere in the page
  • You may need to adjust your page's content security policy to allow scripts and images from beamimpact.com.

NPM

npm install @beamimpact/web-sdk

Import the component in your app's JavaScript:

import { BeamCommunityImpact } from "@beamimpact/web-sdk/dist/components"; // Native web component
import { BeamCommunityImpact } from "@beamimpact/web-sdk/dist/react"; // React component

Using Beam

Web Components

Beam web components are custom elements, so they can be used in HTML:

<beam-impact-overview chainId="1000"></beam-impact-overview>

Because they are standard HTML elements, Beam components can have attributes like class, style, and data-attributes.

Components can also be created using Javascript:

const component = document.createElement("beam-select-nonprofit");
component.chainId = 1000;
component.apiKey = "abc123";
const parent = document.querySelector("#sidebar-cart .footer");
parent.appendChild(component);

The elements can also have children which show up before the script loads or if it fails to parse:

<beam-impact-overview chainId="1000"> Fallback or loading content </beam-impact-overview>

React

Beam provides a React wrapper for the web components.

Key differences: event handler callbacks are exposed for the Beam events, and the components are named using the JSX-friendly uppercase format.

import { BeamSelectNonprofit } from "@beamimpact/web-sdk/dist/react";
import { events } from "@beamimpact/web-sdk/dist/integrations/utils";

<BeamSelectNonprofit
  apiKey={"abc-123"}
  chainId={1000}
  onNonprofitSelect={(event: events.BeamNonprofitSelectEvent) => {
    const { selectedNonprofitId, nonprofitName } = event.detail;
    // do something
  }}
/>;

Serverside-Rendering

(ie, NextJS)

The Beam components run clientside and save data (such as the user's nonprofit selection) in localStorage and cookies.

Use next/dynamic to lazy-load components async on the client instead of the server.

"use client";
import dynamic from "next/dynamic";

const BeamSelectNonprofit = dynamic(() => import("@beamimpact/web-sdk/dist/react/select-nonprofit"), {
  loading: () => null,
  ssr: false,
});

Debug Mode

Add the debug attribute to a component to show an error state in the DOM when errors occur. Otherwise, check for console logs.

<beam-impact-overview chainId="1000" debug></beam-impact-overview>

Component Options

Required props for all components:

  • apiKey - Beam API Key

Optional props:

  • baseUrl - (provided by Beam) - URL for a dev or staging API
  • lang - en, fr, etc. Language code for a Beam-supported translation target

beam-community impact

Shows impact progress cards for each nonprofit supported by a brand, for brand impact pages, etc.

<beam-community-impact apiKey="abc123" chainId="1" cardStyle="image | icon"></beam-community-impact>
  • chainId = Beam customer ID
  • cardStyle = image or icon - visual style to use for impact cards

beam-cumulative-impact

Shows total impact in terms of nonprofit funding goals - e.g., "9,000 lbs of ocean trash removed"

<beam-cumulative-impact apiKey="abc123" chainId="1"></beam-cumulative-impact>
  • chainId = Beam customer ID

beam-select-nonprofit

Component that integrates into a cart to allow users to support a nonprofit as they check out.

<beam-select-nonprofit apiKey="abc-123" storeId="1"> Select a nonprofit </beam-select-nonprofit>
  • storeId = Beam ID for site, i.e., EU or US online store (optional) - used to show relevant nonprofits to users
  • countryCode & postalCode = If storeId is not provided, location information can be provided instead (optional)
  • cart = Usually set automatically by the cart integration (see below), the cart property allows customizing the nonprofits shown based on the items in the cart

Events

document.addEventListener("beamnonprofitselect", (evt) => {
  const { selectedNonprofitId, selectionId, nonprofitName } = evt.detail;
  // ...
});

Event Types

Select Nonprofit Component & Post Purchase Component

  • Event: beamnonprofitselect
  • Description: Emitted when the end user selects a nonprofit in the Beam component, and when the previous selection was restored automatically

Select Nonprofit Component

  • Event: beamcartchange

  • Description: Emitted when Beam detects that cart contents have changed, and when items are added to the cart for the first time

  • Event: beamnonprofitselectionremoved

  • Description: Emitted when the nonprofit selection is removed from deselection or due to nonprofit cohort change

Statsig / A/B Experiment

  • Event: beamstatsiginitialized
  • Description: Emitted when Statsig has completed assigning experiment variants for the current session. Contains showBeam (whether components should be shown) and stableId (the Statsig session Id).

Post Purchase Component

  • Event: beamordercreated
  • Description: Emitted when an order is registered with Beam for the first time, but NOT on repeat visits, page refreshes, etc.

beam-post-purchase

A wrapper component that registers transactions and renders either the beam-impact-overview or beam-redeem-transaction component, depending on if the user made a selection before purchase or not.

<script src="https://sdk.beamimpact.com/web-sdk/v1.36.1/dist/components/post-purchase.js"></script>

<beam-post-purchase apiKey="abc123"></beam-post-purchase>
const component = document.createElement("beam-post-purchase");

// Config values:
component.apiKey = "abc123"; // Required
component.storeId = 100; // Beam Store ID
component.countryCode = "GB"; // 2-letter country code for order
component.postalCode = "11111"; // String - postalCode in country-specific format
component.orderId = String(10101); // partner provides ID
component.email = "[email protected]"; // user email
component.cartTotal = 100.01; // Cart total before tax
component.currencyCode = "USD"; // "CAD" etc.
component.cart = {
  schema: {
    source: "shopify",
  },
  content: {
    items: [{ sku: "PRODUCT-100" }],
  },
}; // see OpenAPI spec for cart formats
component.discountCodes = ["PROMO10", "CLEARANCE_50"]; // discount / promo codes
component.lang = "en"; // en | fr Language
component.domain = "example.com"; // [Optional] Base domain of the store, if subdomains for store and checkout differ
component.debug = false; // boolean

Events

document.addEventListener("beamnonprofitselect", (evt) => {
  const { selectedNonprofitId, nonprofitName } = evt.detail;
  // ...
});

Customizing inner components

Use beam-post-purchase::part(impact-overview) or beam-post-purchase::part(redeem-transaction) to apply CSS.

Integrations

Cart Integration

Integrating Beam with your cart allows for customizing the available nonprofits based on the items in the cart.

import { updateCart } from "https://sdk.beamimpact.com/web-sdk/v1.36.1/dist/integrations/cart.js";

// on cart change
const cart = {
  cartId: "cart_100", // external cart ID (from partner site, optional)
  subtotal: 90,
  itemCount: 1,
  currencyCode: "USD",
  content: {
    items: [
      { remoteProductIdentifier: "sku-123", localAmount: 50 },
      { remoteProductIdentifier: "sku-456", localAmount: 40 },
    ],
  },
};

const beamConfig = {
  apiKey: "abc-123",
  storeId: 123,
  domain: "my-tld.com", // optional, domain or subdomain to set cookies on
  baseUrl: "", // optional, Beam API url (staging or production)
};

await updateCart(beamConfig, cart);

Shopify

The registerCartIntegration() function integrates the Beam Nonprofit Select component with the Shopify cart, which allows Beam metadata for the nonprofitId and selectionId to be added to the order as the user goes through the checkout flow, and to track the cart token and cart value for the Beam ROI calculation.

Add event tracking script to main layout:

<script type="module" async crossorigin>
  import { registerCartIntegration } from "https://sdk.beamimpact.com/web-sdk/v1.36.0/dist/integrations/shopify.esm.js";

  registerCartIntegration({
    apiKey: "abc123",
    storeId: 100,
    chainId: 10,
  });
</script>

Post-purchase script:

import { showBeamOrderPageWidgets } from "https://sdk.beamimpact.com/web-sdk/v1.36.0/dist/integrations/shopify.esm.js";

await showBeamOrderPageWidgets({
  apiKey: beam.apiKey,
  chainId: beam.chainId,
  storeId: beam.storeId,
  orderId, // From Liquid
  email, // From Liquid
  cartTotal, // From Liquid
  cart, // Cart line items
  currencyCode, // From Liquid
  countryCode, // From Liquid
  postalCode, // From Liquid
  parentSelector: ".step__sections", // CSS selector
  lang: "en", // From Liquid
  baseUrl: beam.baseUrl,
  debug: false,
});

Consent-driven teardown:

If a user withdraws tracking consent, unregisterCartIntegration() stops the listeners set up by registerCartIntegration() and can optionally wipe Beam's local storage/cookies in the same call. It's opt-in — the SDK doesn't watch for a consent signal itself, so this must be wired into your own consent banner/flow.

import { unregisterCartIntegration } from "https://sdk.beamimpact.com/web-sdk/v1.36.0/dist/integrations/shopify.esm.js";

await unregisterCartIntegration(
  { apiKey: "abc123", storeId: 100, chainId: 10 },
  { clearStorage: true }, // also clear Beam's localStorage/cookies; defaults to false
);

Utils

Several utilities are exposed which making integrating with existing applications easier.

  1. waitForElement returns a Promise which resolves when the selector appears.
  2. errors contains Beam custom error classes.
  3. events contains Beam custom events classes / event names.
  4. clearBeamStorage clears all Beam-related localStorage keys and cookies for a given config; useful for a standalone consent-driven reset that isn't tied to unregisterCartIntegration.
import { clearBeamStorage } from "https://sdk.beamimpact.com/web-sdk/v1.36.1/dist/integrations/utils.js";

clearBeamStorage({ apiKey: "abc123", domain: "my-store.com" });
import { waitForElement, errors, events } from "https://sdk.beamimpact.com/web-sdk/v1.36.1/dist/integrations/utils.js";

try {
  const parentElement = await waitForElement("#my-selector", { timeout: 1000 });
  parentElement.appendChild(component);
} catch (err) {
  if (err instanceof errors.BeamError) {
    /* do something */
  }
}

window.addEventListener(BeamNonprofitSelectEvent.eventName, async (event) => {});

Integrations

Statsig A/B Testing

Beam has a prebuilt integration for A/B testing with Statsig.

import { StatsigPlugin } from "@beamimpact/web-sdk/dist/integrations/statsig";
import { init, getConfig } from "@beamimpact/web-sdk/dist/integrations/beam";

const beam = await init({
  apiKey: "",
  chainId: 1,
  storeId: 1,
  domain: "my-store.com", // in case site uses subdomains for different pages
  plugins: [new StatsigPlugin({ statsigApiKey: "" })],
});

Initializing the Statsig plugin will automatically log statsig_init, cart_created, and order_created events.

To manually log additional events:

beam.plugins.statsig.logEvent(eventName, eventValue, metadataObject);

Setup for A/B tests is async. Waiting for Beam A/B test setup to be ready in other scripts:

const beam = getConfig();
// Wait for promise to resolve
await beam.readyPromise; // resolves when plugins are all ready
// OR use event listeners
if (beam.status !== "ready") {
  beam.addEventListener("beamstatuschange", (event) => {
    const status = event.detail.status;
    if (status === "ready") doSomething(beam);
    else if (status === "error") handleError(event.detail.error);
  });
}
Visibility

Once initialized, all Beam components have display: none unless user is assigned to A/B test group that shows Beam.

To hide additional elements, add the CSS className beam-sync-visibility to them. Elements with this class will automatically have display: none if the user can't see Beam.

To access the experiment state in JavaScript:

import { getConfig } from "@beamimpact/web-sdk/dist/integrations/beam";

getConfig().plugins.statsig.experiments.shouldShowBeam; // boolean

版本与发布记录

@beamimpact/web-sdk 共发布 79 个版本,首次发布于 2023/11/07;过去 12 个月发布了 20 个版本。

版本发布日期距今
1.58.4latest2026/11/035 天前
1.58.32026/10/2810 天前
1.58.22026/10/2316 天前
1.58.12026/10/031 个月前
1.58.02026/09/281 个月前
1.57.52026/09/042 个月前

关于 @beamimpact/web-sdk 的常见问题

@beamimpact/web-sdk 是什么?

The Beam SDK enables brands to connect with their users over shared values, not transactional discounts, to build stronger loyalty. Our integration achieves this by allowing users to (a) choose a nonprofit where the brand will donate part of their purchas

如何安装 @beamimpact/web-sdk?

在项目目录运行 npm install @beamimpact/web-sdk,或使用 pnpm add / yarn add / bun add。

@beamimpact/web-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@beamimpact/web-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@beamimpact/web-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 18.x || 20.x || 22.x || 24.x。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@beamimpact/web-sdk 可以商用吗?

@beamimpact/web-sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@beamimpact/web-sdk 的下载量有多少?

根据 npm 官方下载统计,@beamimpact/web-sdk 在 2026/10/08 – 2026/11/06 这 30 天内被下载 18,959 次,日均约 632 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@beamimpact/web-sdk 还在维护吗?

最新版本 1.58.4 发布于 2026/11/03(5 天前);至今共发布 79 个版本,其中过去 12 个月发布了 20 个;首次发布于 2023/11/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。