Guide: Building Interactive Marketing Tools

This document outlines the standard structure and component usage patterns for creating interactive calculation/estimation tools within the marketing site, based on the example of the “SaaS Valuation Multiple Estimator”.

Goal

To create reusable, consistent, and maintainable interactive tools that integrate seamlessly with the Astro marketing site structure. The core interaction is typically handled by React components loaded client-side.

Standard File Structure

A typical tool will reside in its own directory within apps/marketing/src/pages/tools/, for example, saas-valuation-multiple-estimator/. The key files are:

Page Entry Point (index.astro)

Interactive Calculator (calculator.tsx)

Common Components (common/)

inputs.tsx

summary.tsx

Content (description.mdx)

Workflow Summary

  1. Page Load: User accesses the /tools/tool-name/ URL. index.astro renders the layout, static text, and placeholders for React components.
  2. Client-Side Hydration: The React component (Calculator) specified with client:load (or similar) hydrates.
  3. Initial State: The useQueryParamState hooks within Calculator read initial values from the URL query parameters (or use defaults). The component renders with these initial values.
  4. User Interaction: The user types into the Input fields.
  5. State Update: The Input component’s onChange handler provides the parsedValue to the Calculator. The Calculator’s state setter (from useQueryParamState) updates the React state and the URL query parameter.
  6. Calculation: The useEffect hook in Calculator, dependent on the input state variables, re-runs. It performs calculations based on the new input values.
  7. Result Update: The calculation results update state variables used by the Summary component.
  8. Re-render: React re-renders the Calculator component, updating the Input values (if formatted) and the Summary display with the new results.