This example demonstrates how to integrate Formo SDK 1.26.0 with Dynamic.xyz wallet for comprehensive web3 analytics.
- Dynamic.xyz Wallet Integration: Connect any wallet using Dynamic's multi-chain wallet infrastructure
- Formo Analytics with Wagmi: Automatic tracking of wallet events via wagmi integration
- Auto-captured Events: Connect, disconnect, chain changes, signatures, and transactions
- Custom Event Tracking: Track custom events with properties
- Page View Tracking: Track page visits
- User Identification: Associate wallet addresses with user sessions
- React 18 - UI framework
- Vite - Build tool
- TypeScript - Type safety
- Tailwind CSS - Styling
- wagmi v2 - React hooks for Ethereum
- viem - TypeScript interface for Ethereum
- Dynamic.xyz SDK - Wallet connection
- Formo SDK 1.26.0 - Web3 analytics
- Dynamic.xyz Account: Get your environment ID at app.dynamic.xyz
- Formo Account: Get your write key at app.formo.so
git clone https://github.com/getformo/examples.git
cd examples/with-dynamicnpm installcp .env.example .envEdit .env and add your keys:
VITE_DYNAMIC_ENVIRONMENT_ID=your_dynamic_environment_id_here
VITE_FORMO_WRITE_KEY=your_formo_write_key_herenpm run devVisit http://localhost:5173 to see the app.
with-dynamic/
├── src/
│ ├── components/
│ │ └── WalletDemo.tsx # Main demo component with wallet actions
│ ├── config/
│ │ ├── dynamic.ts # Dynamic.xyz configuration
│ │ ├── formo.ts # Formo SDK configuration
│ │ └── wagmi.ts # wagmi config with supported chains
│ ├── App.tsx # Main app with providers setup
│ ├── main.tsx # Entry point
│ └── index.css # Global styles
├── package.json
├── vite.config.ts
├── tailwind.config.js
└── tsconfig.json
The app uses a layered provider architecture:
<DynamicContextProvider> {/* Dynamic.xyz wallet provider */}
<WagmiProvider> {/* wagmi state management */}
<QueryClientProvider> {/* React Query for caching */}
<FormoAnalyticsProvider> {/* Formo analytics with wagmi integration */}
<DynamicWagmiConnector> {/* Connects Dynamic to wagmi */}
<App />
</DynamicWagmiConnector>
</FormoAnalyticsProvider>
</QueryClientProvider>
</WagmiProvider>
</DynamicContextProvider>Formo SDK integrates with wagmi to automatically capture wallet events:
<FormoAnalyticsProvider
writeKey={FORMO_WRITE_KEY}
options={{
wagmi: {
config: wagmiConfig, // wagmi config instance
queryClient, // React Query client for mutation tracking
},
autocapture: true, // Enable auto-capture of all wallet events
}}
>When autocapture is enabled, Formo automatically tracks:
| Event | Description |
|---|---|
connect |
Wallet connection |
disconnect |
Wallet disconnection |
chain |
Network/chain changes |
signature |
Message signing (personal_sign, eth_signTypedData_v4) |
transaction |
Transaction sending (eth_sendTransaction) |
page |
Page views |
You can also track custom events using the useFormo hook:
import { useFormo } from '@formo/analytics'
function MyComponent() {
const formo = useFormo()
// Track custom event
await formo.track('button_click', { buttonId: 'cta-main' })
// Track page view
await formo.page('category', 'page_name', { custom: 'properties' })
// Identify user
await formo.identify({ address: '0x...', userId: 'user123' })
}Initialize Formo analytics (automatically called by FormoAnalyticsProvider).
Access the Formo instance in React components.
| Method | Description |
|---|---|
track(event, properties?) |
Track custom event |
page(category?, name?, properties?) |
Track page view |
identify(params) |
Identify user |
connect(params) |
Manually track wallet connect |
disconnect(params?) |
Manually track wallet disconnect |
chain(params) |
Manually track chain change |
signature(params) |
Manually track signature event |
transaction(params) |
Manually track transaction event |
interface Options {
wagmi?: {
config: WagmiConfig; // Required for wagmi integration
queryClient?: QueryClient; // Required for signature/transaction tracking
};
autocapture?: boolean | {
connect?: boolean;
disconnect?: boolean;
signature?: boolean;
transaction?: boolean;
chain?: boolean;
};
tracking?: boolean | {
excludeHosts?: string[];
excludePaths?: string[];
excludeChains?: number[];
};
logger?: {
enabled?: boolean;
levels?: ('info' | 'warn' | 'error')[];
};
}This example supports the following chains (configurable in src/config/wagmi.ts):
- Ethereum Mainnet
- Polygon
- Arbitrum
- Optimism
- Base
- Sepolia (testnet)
Configure your Dynamic.xyz environment in their dashboard:
- Create an account at app.dynamic.xyz
- Create a new project
- Enable the chains you want to support
- Copy your Environment ID to
.env
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Lint code
npm run lint- Formo Documentation
- Formo SDK GitHub
- Dynamic.xyz Documentation
- wagmi Documentation
- viem Documentation
MIT