# How to Capture Your Leads Through the Lynn’s Widgets

The Lead Capturing feature allows users to collect leads directly from their widget. This feature lets you capture essential user details such as email addresses, phone numbers, and other custom fields. You can customize messages displayed to users during the lead capture process and integrate these leads directly into your system using webhooks.

## How to Enable Lead Capturing

1. **Access the Lead Capture Settings:**
   * Navigate to the widget settings where you want to enable lead capturing.
2. **Enable Lead Capturing:**
   * Toggle the **Enable Lead Capturing** switch to turn on the lead capture feature.
3. **Export Captured Leads:**
   * Here you can use the **Export Captured Leads** button to download all captured leads in a CSV format.

<figure><img src="/files/Av9uxao8wftuVUiS7dbv" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/uQF8V1xtPAYwSnebrkQL" alt=""><figcaption></figcaption></figure>

### Customizing Messages and Fields

1. **Customize Acknowledgement and Session End Messages:**
   * **Acknowledgment Message:** This message is displayed to users before collecting their details. Here you can edit the text to create a welcoming message.
   * **Session End Message:** This message is shown after collecting user details. Customize it to thank users or inform them of the next steps.
2. **Configure Fields to Capture:**
   * Click on the **Fields to Capture** section to add or edit fields.
   * **Add Field:** Once you select the field type from the Text, Number, Email, or Mobile Number fields, you can add the field to the questionnaire by clicking on this button.
   * For each field, set:
     * **Request Message:** The prompt shown to users asking for their information.
     * **Appreciation Message:** A confirmation message is shown after the user provides their details. Use placeholders like `{{value}}` to dynamically insert user-provided information.

<figure><img src="/files/xLXaShkueCgohtQkNv3Z" alt=""><figcaption></figcaption></figure>

### Integrating with Webhooks

1. **Webhook Connection:**

   * To integrate lead data into your system in real-time, connect your widget to a webhook.
   * **Enter the Webhook URL:** Provide the endpoint URL where lead data will be sent.
   * **Secret Key:** For security purposes, use the provided secret key in your server to verify the authenticity of incoming requests.

   When a lead is captured through Lynn's widget, the information is sent via a webhook. Here’s a breakdown of the webhook body content:

   ```jsx
   {
     "workspaceId": "qprBF5koDdOjmdCPikl2",
     "widgetId": "fwanJl2WUoFqqUkilAKe",
     "leadCaptureId": "RCvTDLf0K3qLN1or3S5Z",
     "fieldValues": {
       "eCQUiOd7YbIGQei0ZMA1o": "Kumuthu",
       "fLR4QPLDMIDaL3jsaKGmI": "email@lynn.chat"
     },
     "createdAt": "2024-09-01T14:31:59.906Z"
   }
   ```

   * **workspaceId**: Unique identifier for your Lynn workspace.
   * **widgetId**: Identifier for the widget that captured the lead.
   * **leadCaptureId**: Unique ID for the lead capture event.
   * **fieldValues**: Contains the captured user data with a unique fieldId (e.g., name, email).
   * **createdAt**: Timestamp of when the lead was captured.

   You may use this data to integrate captured leads into your CRM or database.

   #### Receiving the Request

   You can easily get the information you need from the request body, just like you would with any request. However, for added security and to prevent spam from people who are aware of your endpoint, it's a good idea to check the `x-lynn-hmac-sha256` in the request header. This helps ensure that only legitimate requests are processed.

   To verify the data's authenticity, encrypt the entire request body using `HMAC-SHA256` with a `secret key` that Lynn’s admin portal. Then compare the generated signature with the `x-lynn-hmac-sha256` value in the request headers. If they match, it confirms the message's legitimacy.

   The following Next.js code example demonstrates a secure way to handle webhook requests.

   [Next.js](/how-to-capture-your-leads-through-the-lynns-widgets/next.js.md)
2. **Testing the Webhook:**
   * Once the webhook is connected, conduct tests to ensure that lead data is correctly being sent and received.

### Managing and Exporting Leads

* All captured leads can be reviewed and exported from the widget’s settings. Ensure your settings are correctly configured to prevent data loss and ensure compliance with data privacy regulations.

**Note**

* Once you change the schema or the set of questions for lead capturing, the leads collected under the previous schema will be cleared. Therefore, we strongly recommend downloading the already captured leads before making any changes to the question schema.
* The questionnaire will appear as soon as a user starts a conversation with Lynn, before Lynn responds to the user's first message.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.lynn.chat/how-to-capture-your-leads-through-the-lynns-widgets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
