> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fetchski-attract.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Conversions the page can fire (public)

> Anonymous and read-only: what the site’s own pages load to fire conversions in the browser.

```ts AdonisJS wrap theme={"dark"}
import app from '@adonisjs/core/services/app'
import { SiteClient } from '@fetchski/attract-cms-sdk'

const site = await app.container.make(SiteClient)
const listActiveConversions = await site.conversions().listActiveConversions()
```

```json 200 wrap theme={"dark"}
{
  "conversions": [
    {
      "id": "ckq1w2e3r4t5y6u7i8o9p0",
      "key": "phone-call",
      "counting": "once",
      "value": null,
      "currency": "USD",
      "sendUserData": true,
      "destinations": [
        "google-ads",
        "ga4"
      ],
      "platforms": {
        "google-ads": {
          "sendTo": "AW-123456789/AbC-D_efG"
        },
        "ga4": {
          "event": "contact"
        }
      },
      "triggers": {
        "forms": [],
        "links": [
          "tel:*"
        ],
        "outbound": false,
        "downloads": [],
        "chat": [],
        "pageView": false
      }
    }
  ]
}
```

## In your app

A controller answers a route on your app: it calls `listActiveConversions()` and returns the answer.

**1. Add the controller**

```ts app/controllers/list_active_conversions_controller.ts theme={"dark"}
import { inject } from '@adonisjs/core'
import { SiteClient } from '@fetchski/attract-cms-sdk'

@inject()
export default class ListActiveConversionsController {
  constructor(protected site: SiteClient) {}

  async handle() {
    return this.site.conversions().listActiveConversions()
  }
}
```

**2. Add the route**

```ts start/routes.ts theme={"dark"}
import router from '@adonisjs/core/services/router'

const ListActiveConversionsController = () => import('#controllers/list_active_conversions_controller')

router.get('/conversion/active', [ListActiveConversionsController])
```

**3. Call it**

```bash Terminal theme={"dark"}
curl http://localhost:3333/conversion/active
```

With `node ace serve` running, it prints its answer as JSON.

Each enabled Conversion with a browser trigger, compiled, with only its rows sent from the page and its page-view triggers resolved against `path` to a yes/no. No names, no server-only IDs, and never the site’s page list. Integrations should use `GET /conversion/definitions` instead.

> [accordion] Optional parameters
>
> One object, e.g. `listActiveConversions({ path })`; leave out the optional fields.
>
> **path** `string | null | undefined`
>
> **Optional.** Leave it out and the site uses `"/"`. The page path the conversions are for. Default `/`. At most 2048 characters.

> [accordion] Returns
>
> A `ListActiveConversionsResponse`. The page’s conversions. Read its properties (`listActiveConversions.conversions`): each says whether the site always sends it.
>
> **conversions** `readonly ListActiveConversionsResponseConversionsItem[]`
>
> **Always sent.** A list of `ListActiveConversionsResponseConversionsItem`.
>
> **ListActiveConversionsResponseConversionsItem**
>
> **id** `string`
>
> **Always sent.**
>
> **key** `string`
>
> **Always sent.** The Conversion’s key, sent to Google Analytics and Tag Manager as `conversion_key`.
>
> **counting** `Counting`
>
> **Always sent.** One of `once`, `every`; a newer site may send others, so keep a fallback.
>
> **value** `number | null`
>
> **Always sent, can be `null`.**
>
> **currency** `string`
>
> **Always sent.**
>
> **sendUserData** `boolean`
>
> **Always sent.**
>
> **destinations** `readonly Destinations[]`
>
> **Always sent.** The platforms the page sends this Conversion to. Each one of `google-ads`, `ga4`, `gtm`, `meta`, `tiktok`.
>
> **platforms** `Readonly\<Record\<string, ListActiveConversionsResponseConversionsItemPlatformsValue\>\>`
>
> **Always sent.** A map of names to `ListActiveConversionsResponseConversionsItemPlatformsValue`. Per platform in `destinations`, what its tag needs: the event name (GA4, GTM, Meta, TikTok), or the Google Ads `send_to`.
>
> **ListActiveConversionsResponseConversionsItemPlatformsValue**
>
> **event** `string`
>
> **Sometimes sent:** `undefined` when the site leaves it out.
>
> **sendTo** `string`
>
> **Sometimes sent:** `undefined` when the site leaves it out.
>
> **conversionId** `string`
>
> **Sometimes sent:** `undefined` when the site leaves it out.
>
> **triggers** `ListActiveConversionsResponseConversionsItemTriggers`
>
> **Always sent.** A `ListActiveConversionsResponseConversionsItemTriggers`.
>
> **ListActiveConversionsResponseConversionsItemTriggers**
>
> Required.
>
> **forms** `readonly string[]`
>
> **Always sent.**
>
> **links** `readonly string[]`
>
> **Always sent.** Link patterns: a scheme (`tel:*`, `tel:+15550100100`), a full address (may end in `*`), a `/path` of this site, or a domain.
>
> **outbound** `boolean`
>
> **Always sent.** Fires on any link that leaves the site.
>
> **downloads** `readonly string[]`
>
> **Always sent.** File extensions whose links fire it, e.g. `pdf`.
>
> **chat** `readonly Chat[]`
>
> **Always sent.** Each one of `chat-started`, `lead-captured`.
>
> **pageView** `boolean`
>
> **Always sent.** Whether viewing `path` fires it.

> [accordion] Errors
>
> Nothing to catch: the SDK retries what is safe, and throws the rest as the classes below. Your exception handler turns them into your app’s own answers, once for every call (see [Map SDK errors to responses](https://docs.fetchski-attract.com/adonisjs/calling-the-api.md#map-sdk-errors-to-responses)); catch only what you want to react to here.
>
> **SiteError** `5xx`
>
> The site failed (or something in front of it did). Its logs say why.
>
> **Retried first:** A 502, 503 or 504: yes, after 0.5 s then 1 s. A 500: no. **Read:** `siteMessage`, `errorName`, `data`.
>
> **SiteUnreachable** `no answer`
>
> No answer: DNS, a refused connection, TLS, or the timeout (15 s per attempt by default).
>
> **Retried first:** Yes, after 0.5 s then 1 s. **Read:** `reason`, `neverConnected`.
>
> **RequestNotSent** `not sent`
>
> The client refused to send it (e.g. a path segment of `..`); the site never saw it.
>
> **Retried first:** No. **Read:** `reason` (what to change).
>
> **SiteRequestFailed** `any other`
>
> Any other status, or a success whose JSON doesn’t match this SDK version’s types (update the SDK).
>
> **Retried first:** No. **Read:** `reason`, `status`.
>
> **UnknownSite** `setup`
>
> `sites.forSite('acme')` named a slug `config/attract.ts` doesn’t list (with the keys in the database: no row in `attract_api_keys`).
>
> **Retried first:** No: nothing was sent. **Read:** `message`, `slug`.
>
> **SiteConfigurationError** `setup`
>
> The site’s entry is wrong: a malformed `baseUrl` or key, a key filed under another slug, or no default site. `node ace attract:check` names the fix.
>
> **Retried first:** No: nothing was sent. **Read:** `message` (what to fix).

## Behavior

* **Retries:** a read is safe to repeat: the client retries it on no answer, a 502/503/504 and a 429.
* **Timeout:** 15 s per attempt by default; raise `timeout` (milliseconds) in `config/attract.ts` for longer.

## Test it

It calls the controller above with the SDK faked: `fakeAttract()` puts the fake in the container for this one test, and it answers every call with a valid example, so nothing leaves your machine and no key is read. Save it as `tests/unit/conversions_list_active_conversions.spec.ts`, then run your tests:

```ts tests/unit/conversions_list_active_conversions.spec.ts theme={"dark"}
import { test } from '@japa/runner'
import app from '@adonisjs/core/services/app'
import { fakeAttract } from '@fetchski/attract-cms-adonis/testing'
import ListActiveConversionsController from '#controllers/list_active_conversions_controller'

test('conversions.listActiveConversions', async () => {
  const site = fakeAttract()

  const controller = await app.container.make(ListActiveConversionsController)
  await controller.handle()

  site.assertCalled('conversions.listActiveConversions')
})
```

```bash Terminal theme={"dark"}
node ace test
```

## Related

> [card] [List the enabled Conversions](https://docs.fetchski-attract.com/adonisjs/reference/conversions/list-conversion-definitions.md)
>
> `site.conversions().listConversionDefinitions()`

> [card] [GET /conversion/active](https://docs.fetchski-attract.com/api-reference/conversions/conversions-the-page-can-fire-public.md)
>
> The endpoint this calls, in the API reference: the HTTP request and answer, and every rule the site checks.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.