@beamimpact/web-sdk
Version:
The Beam SDK enables brands to connect with their customers over shared values, not transactional discounts, to build stronger loyalty. Our integration achieves this by allowing customers to (a) choose a nonprofit where the brand will donate part of their
57 lines (54 loc) • 1.92 kB
TypeScript
import { BeamPlugin, BeamConfigOptions } from './beam.js';
import '../chunks/types-CPxMwnoR.esm.js';
type beforeLogEventFn = (eventName: string, eventValue: any, metadata: Record<string, any>) => Record<string, any>;
/**
* StatSig Docs: https://docs.statsig.com/client/jsClientSDK
*/
type StatsigPluginOptions = {
statsigApiKey: string;
beforeLogEvent?: beforeLogEventFn;
};
declare global {
interface Window {
statsig?: any;
}
}
type Experiments = {
/** Whether Beam widgets should be shown to users */
shouldShowBeam: boolean;
/** Whether events should be logged to Statsig */
isLoggingEnabled: boolean;
};
/**
* Sets up Statsig for A/B testing and shows/hides Beam based on default experiment rules.
* @example
* import { StatsigPlugin } from '@beamimpact/web-sdk/dist/integrations/statsig'
* import { init } 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: '' })
* ]
* })
*
* // Once initialized, all Beam widgets 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
* // To programmatically access the experiment state: getConfig().plugins.statsig.experiments.shouldShowBeam
*/
declare class StatsigPlugin implements BeamPlugin {
#private;
name: string;
statsig: any;
statsigApiKey: string;
experiments: Experiments;
stableId?: string;
beforeLogEvent?: beforeLogEventFn;
constructor(options: StatsigPluginOptions);
init(config: BeamConfigOptions): Promise<void>;
logEvent(name: string, value: string | number | boolean, metadata?: Record<string, any>): void;
}
export { StatsigPlugin };