# Preflight Check: Custom Function (/docs/dsr-automation/preflight-and-enrichment/preflight-checks/preflight-check-custom-function-enricher)

## Overview [#overview]

Use a DSR Custom Function enricher to add identifiers or change the preflight request state before DSR processing begins.

For complete Custom Function documentation, see [Introduction to Custom Functions](../../../custom-functions-overview/introduction-to-custom-functions.mdx).

### Configuration Steps [#configuration-steps]

Before getting started, you'll need a DSR custom function connected to your data system. Follow [Custom Function Creation Methods](../../../custom-functions-overview/custom-function-usecases.mdx), then add the `enricher` export described below.

Export a named `enricher` function. It receives the same `environment`, `sdk`, and `kv` arguments as DSR data-point processing, but its `payload` uses the [preflight webhook request shape](/docs/api-reference/webhooks/webhook-new-preflight-request-job).

```typescript
import type { CustomFunction } from '@transcend-io/custom-function-types';

export async function enricher({
  environment,
  payload,
  sdk,
}: CustomFunction.EnricherArgument): Promise<void> {
  console.info(`Enriching identifier type: ${payload.requestIdentifier.name}`);

  const response = await sdk.fetch('/v1/enrich-identifiers', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${environment.TRANSCEND_PLATFORM_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      enrichedIdentifiers: {
        googleAnalyticsInternalId: [
          { value: 'SOME-GOOGLE-ANALYTICS-ID' },
        ],
        gpadvid: [
          { value: 'b20f48d8-9f50-447a-a446-1d398a9f9b1b' },
        ],
      },
    }),
  });

  if (!response.ok) {
    throw new Error(
      `Failed to enrich identifiers (${response.status}): ${await response.text()}`,
    );
  }
}
```

The SDK supplies the internal Custom Function authorization and workflow nonce. The request body may include enrichedIdentifiers and may also include a supported preflight status or template selection. Always check response.ok because sdk.fetch does not throw for HTTP error responses.

Store a Transcend API key in the function's environment variables and send it as the bearer token. The key requires the `Manage Request Identity Verification` scope.

The same DSR Custom Function may handle both preflight enrichment and data-point processing. The named `enricher` export runs during preflight checks, and the `default` export runs during DSR processing. A preflight-only function may omit the `default` export, and a processing-only function may omit `enricher`.

<Callout type="info" title="Preflight testing">
  Use the DSR Custom Function editor's **Testing** tab. Select the Preflight (`enricher`) panel, provide a preflight payload, and select **Run test**. Test both successful enrichment and failure handling before publishing.
</Callout>

Finally, to complete setup of the Custom Function Enricher, navigate to the [Identifiers](https://app.transcend.io/privacy-requests/identifiers) page in the Admin Dashboard, and scroll down to "Preflight & Identity Enrichment". Select the "+" button to create a new preflight check.

![Select "Run a Custom Function" when creating a new preflight check](/images/2025-07-07-select-cf-enricher.png)

Select the Run a Custom Function type, then choose a connected Custom Function integration. Configure the input identifier supplied to the function and the output identifiers expected from it. You can optionally limit the enricher to specific data subjects or configure dependencies.

![Configure the Custom Function preflight check](/images/2025-07-07-configure-cf-enricher.png)
