Skip to main content
For best results, install Formo on both your website (example.com) and your app (app.example.com) using the same project/SDK write key.

Instructions

Set up Formo for both your website and your app on the same project.
  • For static websites (example.com), we recommend using the HTML snippet.
  • For apps (app.example.com) with wallet connection, we recommend using the Wagmi integration.
Make sure you use the same <SDK_WRITE_KEY> for both your website and your app. You can find the write key in your Formo project settings.

1. Install the Formo SDK

  npm install @formo/analytics --save

2. Configure Formo with Wagmi

Pass your Wagmi config and QueryClient to enable native Wagmi integration.
  // App.tsx

  import { WagmiProvider, createConfig, http } from 'wagmi';
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
  import { FormoAnalyticsProvider } from '@formo/analytics';
  import { mainnet } from 'wagmi/chains';

  const wagmiConfig = createConfig({
    chains: [mainnet],
    transports: {
      [mainnet.id]: http(),
    },
  });

  const queryClient = new QueryClient();

  function App() {
    return (
      <WagmiProvider config={wagmiConfig}>
        <QueryClientProvider client={queryClient}>
          <FormoAnalyticsProvider
            writeKey="<SDK_WRITE_KEY>"
            options={{
              wagmi: {
                config: wagmiConfig,
                queryClient: queryClient,
              },
            }}
          >
            <YourApp />
          </FormoAnalyticsProvider>
        </QueryClientProvider>
      </WagmiProvider>
    );
  }
Replace <YOUR_WRITE_KEY> with the SDK Write key found in your project settings.

3. Identify users

Call identify at the start of every session or page load to link a wallet address to a session.
import { useFormo } from "@formo/analytics";
import { useAccount } from "wagmi";

const HomePage = () => {
  const { address } = useAccount();
  const analytics = useFormo();

  useEffect(() => {
    if (address && analytics) {
      analytics.identify({ address });
    }
  }, [address, analytics]);
}

4. Track events (optional)

Formo autocaptures wallet events (connect, disconnect, signature, transaction, chain changes) automatically via Wagmi.Use the track function to track custom user actions specific to your app.
  import { useFormo } from '@formo/analytics';

  const HomePage = () => {
    const analytics = useFormo();

    useEffect(() => {
      // Track a custom event
      analytics.track('Swap Completed', { points: 100 });
    }, [analytics]);

    return <div>Welcome to the Home Page!</div>;
  };

  export default HomePage;

Code Examples

Autocapture

The Formo SDK automatically captures common events such as page views and wallet events (connect, disconnect, signature, transaction, etc) with full attribution (referrer, UTM, referrals.) You do not need to configure anything to track these events.

Verification

To verify that the SDK is installed correctly, navigate to your site and open the network tab of the developer tools in your browser. Go to your browser’s Network tab and and look for successful ‘raw_events’ request in the network console. Check that the request returns a 202 response status. (Note that it may take up to a minute due to the flush interval.) Events that are tracked correctly should also show up in the Activity page of your Formo workspace.

SDK Reference

Support