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

# Facebook conversions export

> Export SegmentStream conversions to your Facebook pixel for improved ad targeting and measurement.

<Steps>
  <Step title="Select a conversion">
    Inside the admin panel, go to the **Conversions** page and select the conversion you want to export as an event to your Facebook pixel.
  </Step>

  <Step title="Add export">
    In the conversion menu, click **Add Export**.

    <img src="https://mintcdn.com/segmentstream/fSGYTtkHEv2DXb5X/images/project-configuration/conversions/conversions-export.png?fit=max&auto=format&n=fSGYTtkHEv2DXb5X&q=85&s=76a83876daa99d4998a420f4ccb99e71" alt="Add export button" width="2390" height="1556" data-path="images/project-configuration/conversions/conversions-export.png" />
  </Step>

  <Step title="Authenticate with Facebook">
    Select **Facebook** in the window that opens and go through the authentication flow.
  </Step>

  <Step title="Configure export settings">
    After the authentication flow, you should see the Facebook export settings.

    * Enter your **Pixel ID** (which can be found inside the [Facebook Events Manager](https://www.facebook.com/events_manager2/)).
    * Fill in the **Event name** for each conversion. We recommend keeping the event name the same as your conversion name within SegmentStream.
    * Choose whether to enable **Enhanced Tracking**, which exports additional user data such as email, name, and other details if available in the conversion data.
    * Choose whether to enable **Retrospective Updates**, which allows exporting conversions retroactively within the set lookback window. This is useful when conversions are exported from your CRM, particularly when conversions are validated several days after they occur.
  </Step>

  <Step title="Save">
    Click **Save**. Conversions will be automatically exported to Facebook daily after data processing for the previous day is completed.
  </Step>
</Steps>

<Info>
  It might take up to 1 hour before you see the first batch of events from SegmentStream.
</Info>

## Cookies custom fields setup

By default, Google Analytics 4 does not collect data about first-party cookies like `_fbp`. This cookie is required to send additional data through server-side conversion tracking.

<Tabs>
  <Tab title="Using GTM">
    <Steps>
      <Step title="Create a cookie variable">
        Inside your Google Tag Manager, go to **Variables**, click **New**, and choose the **1st Party Cookie** variable type from the list.
      </Step>

      <Step title="Configure the variable">
        Name your variable `fbp`, enter `_fbp` in the **Cookie Name** field, and click **Save**.
      </Step>

      <Step title="Add to your Google Tag">
        Open your **Google Tag**, click **Add parameter** in the **Event Parameter** field, and enter the parameter `fbp` with the value `{{fbp}}`.
      </Step>

      <Step title="Publish">
        Click **Save** and **Publish** the container.
      </Step>
    </Steps>
  </Tab>

  <Tab title="Using gtag.js">
    1. Define a global function that dynamically gets the cookie value:

       ```javascript theme={null}
       function getFbpCookie() {
         try {
           return /_fbp=(fb\.1\.\d+\.\d+)/.exec(window.document.cookie)[1];
         } catch (e) {
           return undefined;
         }
       }
       ```

           <Warning>
             It is important to use a function instead of saving to a global variable because sometimes the cookie value might not be available yet (for example, the Facebook Pixel SDK has not loaded).
           </Warning>

    2. Add the parameter to your gtag config call:

       ```javascript theme={null}
       gtag('config', 'G-XXXXXXXXXX', {
         fbp: getFbpCookie(),
         // other params...
       });
       ```

    3. **Optional**. Add the parameter to all other events:

       ```javascript theme={null}
       gtag('event', '<EVENT_NAME>', {
         fbp: getFbpCookie(),
         // other params...
       });
       ```

           <Tip>
             Adding parameters to events may improve tracking in case your gtag config call was triggered before cookies were set.
           </Tip>
  </Tab>
</Tabs>
