Formo
The Formo Web SDK is open source and implements the standard Events API.

Installation

Websites

Install this snippet at the <head> of your website:
<script
  src="https://cdn.formo.so/analytics@latest"
  defer onload="window.formofy('<YOUR_WRITE_KEY>');"
></script>
Enable Subresource Integrity (SRI) to improve site security.

React & Next.js

Install the JavaScript SDK via CDN or NPM.
npm install @formo/analytics --save
// App.tsx (or App.js)

import { FormoAnalyticsProvider } from '@formo/analytics';

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);

root.render(
  <React.StrictMode>
    <FormoAnalyticsProvider writeKey="<YOUR_WRITE_KEY>">
      <App />
    </FormoAnalyticsProvider> 
  </React.StrictMode>
);
// Usage on a page component

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;

Autocapture

The Web 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.

Identify users

Call identify() after a user connects their wallet or signs in on your website or app:
analytics.identify({ address });

OR

window.formo.identify(...);
If no parameters are specified, the Formo SDK will attempt to auto-identify the wallet address.

Track events

Track user actions by calling the track function:
import { useFormo } from '@formo/analytics';

const analytics = useFormo();

analytics.track("Position Opened",  // event name
  {
    pool_id: "LINK/ETH",
    revenue: 99.99,     // revenue
    currency: "USD",    // currency
    points: 99.99        // points for XP or rewards
  }
)

OR 

window.formo.track(...)

Code examples

Configuration

Local testing

The SDK skips tracking in localhost by default. To enable tracking locally during development, set tracking to true:
<AnalyticsProvider
    writeKey={WRITE_KEY}
    options={{
        tracking: true, // enable tracking on localhost
    }}
>

Environments

You can control tracking behavior in different environments (test, staging) with the tracking option:
// Initialize with a boolean (simple on/off)
const analytics = await FormoAnalytics.init('your-write-key', {
  tracking: true // Enable tracking everywhere, including localhost
});

// Initialize only on production environment
const analytics = await FormoAnalytics.init('your-write-key', {
  tracking: ENV === 'production'
});

// Initialize with an object for exclusion rules
const analytics = await FormoAnalytics.init('your-write-key', {
  tracking: {
    excludeHosts: ['stage-v2.puri.fi'], // Exclude tracking based on window.location.hostname
    excludePaths: ['/test', '/debug'], // Exclude tracking based on window.location.pathname
    excludeChains: [5] // Exclude tracking on Goerli testnet (5)
  }
});
Specify exact hostnames and exact paths in exclusion lists.

Logging

Control the level of logs the SDK prints to the console with the following logLevel settings:
<AnalyticsProvider
    writeKey={WRITE_KEY}
    options={{
        logger: {
            enabled: true,
            levels: ["error", "warn", "info"],
        },
    }}
>

Batching

To support high-performance environments, the SDK sends events in batches.
<AnalyticsProvider
    writeKey={WRITE_KEY}
    options={{
        flushAt: 20, // defaults to batches of 20 events
        flushInterval: 1000 * 60, // defaults to 1 min
    }}
>
Customize this behavior with the flushAt and flushInterval configuration parameters.

Ready Callback

The ready callback function executes once the Formo SDK is fully loaded and ready to use. This is useful for performing initialization tasks or calling SDK methods that require the SDK to be ready.
<AnalyticsProvider
    writeKey={WRITE_KEY}
    options={{
        ready: function(formo) {
            // SDK is ready
            console.log('Formo SDK is ready!');            
            formo.identify(); // Auto-identify user
        },
    }}
>
For Browser installations, you can use the ready callback in the onload attribute:
<script
  src="https://cdn.formo.so/analytics@latest"
  defer
  onload="
    window.formofy('<YOUR_WRITE_KEY>', {
      ready: function(formo) {
        formo.identify();
      }
    });
  "
></script>
Log LevelDescription
traceShows the most detailed diagnostic information, useful for tracing program execution flow.
debugShows all messages, including function context information for each public method the SDK invokes.
infoShows informative messages about normal application operation.
warnDefault. Shows error and warning messages.
errorShows error messages only.