# Custom events, goals and revenue

Pageviews are counted automatically. To count actions such as signups, call `foresite()`:

```js
foresite('signup')
```

## Properties

Add properties to break an event down further:

```js
foresite('signup', { props: { plan: 'pro', source: 'pricing-page' } })
```

Properties are shown on the dashboard by event. **Never put personal data in properties.** Values that look like email addresses, phone numbers, card numbers or IP addresses are discarded automatically, and the dashboard warns you if that happens.

## Revenue

Attach an amount to an event to see revenue on the dashboard:

```js
foresite('purchase', { revenue: { amount: 49.99, currency: 'USD' } })
```

The currency must match your site's currency (**Settings → General**). Amounts in any other currency are ignored, so totals are never mixed.

## Calling foresite() before the script loads

If your code might run before Foresite has loaded, add this line once, above your Foresite script:

```html
<script>window.foresite=window.foresite||function(){(foresite.q=foresite.q||[]).push(arguments)}</script>
```

Calls made early are queued and sent as soon as Foresite loads.

## TypeScript

Declare `foresite` once, for example in `global.d.ts`, so TypeScript knows about it:

```ts
declare global {
  interface Window {
    foresite?: (
      name: string,
      options?: {
        props?: Record<string, string | number | boolean>
        revenue?: { amount: number | string; currency: string }
      },
    ) => void
  }
}
export {}
```

Then call it with `window.foresite?.('signup')`. The `?.` skips the call during server rendering, or if an ad blocker stopped the script.

## Goals

A Goal marks a page or an event as a success, such as `/thank-you` or `signup`. Add Goals in **Settings → Goals**; the dashboard then shows how many visitors reached each one, and the conversion rate. Page goals ending in `*` match every page starting with that path, e.g. `/blog/*`.

Custom events count toward your [monthly price](https://foresite.dev/pricing), just like pageviews.
