# Send PostHog conversion events to Meta Ads - Docs

You'll also need access to the relevant Meta Ads account.

## Installation

1.  In PostHog, click the [Data pipeline](https://app.posthog.com/data-management/destinations) tab in the left sidebar.

2.  Click the [Destinations](https://app.posthog.com/data-management/destinations?search=meta) tab.

3.  Search for **Meta Ads Conversions** and click **\+ Create**.

4.  Visit the [Meta Events Manager](https://business.facebook.com/events_manager2/overview).

    1.  If you’ve already set up a Pixel for your website, we recommend that you use the same Pixel ID for your browser and server events.
        1.  To create a new Pixel, click **Connect data** and select **Web**.
        2.  For the connection method, select **Set up manually** and **Conversions API**.
    2.  Go to your Pixel via **Data sources**.
    3.  Switch to the **Settings** tab and your Pixel ID will be listed as **Dataset ID**.
    4.  You can create an access token by clicking **Generate access token**.
5.  Back in PostHog, add the access token and Pixel ID to the destination configuration.

6.  Set up your event and property filters to remove unnecessary events. You only want to send events that are conversions. Filter out unrelated events or ones missing required data.

7.  Press **Create & enable**, test your destination, and then watch your conversions get sent to Meta Ads.

## Configuration

| Option | Description |
| --- | --- |
| Access tokenType: stringRequired: True | Check out this page on how to obtain such a token: [https://developers.facebook.com/docs/marketing-api/conversions-api/get-started](https://developers.facebook.com/docs/marketing-api/conversions-api/get-started) |
| Pixel IDType: stringRequired: True | You must obtain a Pixel ID to use the Conversions API. If you’ve already set up a Pixel for your website, we recommend that you use the same Pixel ID for your browser and server events. |
| Event nameType: stringRequired: True | A standard event or custom event name. |
| Event IDType: stringRequired: True | The ID of the event. |
| Event source URLType: stringRequired: False | The URL of the page where the event occurred. |
| Event timeType: stringRequired: True | A Unix timestamp in seconds indicating when the actual event occurred. You must send this date in GMT time zone. |
| Action sourceType: choiceRequired: True | This field allows you to specify where your conversions occurred. Knowing where your events took place helps ensure your ads go to the right people. |
| User dataType: dictionaryRequired: True | A map that contains customer information data. See this page for options: [https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters) |
| Custom dataType: dictionaryRequired: True | A map that contains custom data. See this page for options: [https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data) |
| Test Event CodeType: stringRequired: False | Use this field to specify that events should be test events rather than actual traffic. You'll want to remove your Test Event Code when sending real traffic through this integration. |

How to create this via the API

Using our REST API you can create this destination like so:

Terminal

PostHog AI

```bash
# Create a new destination
curl --location 'https://us.i.posthog.com/api/environments/:project_id/hog_functions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <POSTHOG_PERSONAL_API_KEY>' \
--data '{
    "type": "destination",
    "name": "Meta Ads Conversions",
    "inputs": {
        "accessToken": {
            "value": ""
        },
        "pixelId": {
            "value": ""
        },
        "eventName": {
            "value": "{event.event}"
        },
        "eventId": {
            "value": "{event.uuid}"
        },
        "eventSourceUrl": {
            "value": "{event.properties.$current_url}"
        },
        "eventTime": {
            "value": "{toInt(toUnixTimestamp(event.timestamp))}"
        },
        "actionSource": {
            "value": "website"
        },
        "userData": {
            "value": {
                "em": "{sha256Hex(lower(person.properties.email))}",
                "fn": "{sha256Hex(lower(person.properties.first_name))}",
                "ln": "{sha256Hex(lower(person.properties.last_name))}",
                "fbc": "{not empty(person.properties.fbclid ?? person.properties.$initial_fbclid) ? f'fb.1.{toUnixTimestampMilli(now())}.{person.properties.fbclid ?? person.properties.$initial_fbclid}' : ''}",
                "client_user_agent": "{event.properties.$raw_user_agent}"
            }
        },
        "customData": {
            "value": {
                "price": "{event.properties.price}",
                "currency": "USD"
            }
        }
    },
    "enabled": true,
    "template_id": "template-meta-ads"
}'
```

## FAQ

### Is the source code for this destination available?

PostHog is open-source and so are all the destination on the platform. The [source code](https://github.com/PostHog/posthog/blob/master/posthog/cdp/templates/meta_ads/template_meta_ads.py) is available on GitHub.

### Who maintains this?

This is maintained by PostHog. If you have issues with it not functioning as intended, please [let us know](https://us.posthog.com/#panel=support%3Asupport%3Aapps%3A%3Atrue)!

### What if I have feedback on this destination?

We love feature requests and feedback. Please [tell us what you think](https://us.posthog.com/#panel=support%3Afeedback%3Aapps%3Alow%3Atrue).

### What if my question isn't answered above?

We love answering questions. Ask us anything via [our community forum](/questions.md).

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better