# Set up SourceTag with Salesforce Web-to-Lead

Canonical: https://sourcetag.io/docs/fields-salesforce-web-to-lead

Salesforce Web-to-Lead generates an HTML form that creates Lead records when submitted. You create custom Lead fields in Salesforce first, include them in the generated form, then convert them to hidden inputs in the HTML.

## What you need

- SourceTag installed on your website
- Salesforce admin access (to create custom fields and generate the Web-to-Lead form)

## Step 1: Create custom Lead fields in Salesforce

1. In Salesforce Setup, go to **Object Manager > Lead > Fields & Relationships**
2. Click **New** to create a custom field
3. For each SourceTag field:
   - Choose **Text** as the data type
   - Set the **Field Label** to a descriptive name (e.g. "ST First Click Channel")
   - Set the **Field Name** (API Name) to match the SourceTag field name if possible (e.g. `st_fc_channel`). Salesforce will append `__c` to create the API name (`st_fc_channel__c`)
   - Set the **Length** to 255 characters
4. Save and assign to the appropriate page layout


### Core fields (create these)

| Field Label | API Name (auto-generated) |
|---|---|
| ST First Click Channel | `st_fc_channel__c` |
| ST First Click Detail 1 | `st_fc_detail_1__c` |
| ST First Click Detail 2 | `st_fc_detail_2__c` |
| ST First Click Detail 3 | `st_fc_detail_3__c` |
| ST First Click Detail 4 | `st_fc_detail_4__c` |
| ST Last Click Channel | `st_lc_channel__c` |
| ST Last Click Detail 1 | `st_lc_detail_1__c` |
| ST Last Click Detail 2 | `st_lc_detail_2__c` |
| ST Last Click Detail 3 | `st_lc_detail_3__c` |
| ST Last Click Detail 4 | `st_lc_detail_4__c` |
| ST First Click Landing | `st_fc_landing_page__c` |
| ST Last Click Landing | `st_lc_landing_page__c` |

### Optional extended fields

| Field Label | API Name (auto-generated) |
|---|---|
| ST First Click ID | `st_fc_click_id__c` |
| ST Last Click ID | `st_lc_click_id__c` |
| ST Visits | `st_visits__c` |
| ST Days to Convert | `st_days_to_convert__c` |
| ST Device | `st_device__c` |

See [Captured Fields](https://sourcetag.io/docs/captured-fields) for the full list of available fields.

## Step 2: Generate the Web-to-Lead form

1. In Salesforce Setup, go to **Marketing > Web-to-Lead** (or search for "Web-to-Lead" in Setup)
2. Click **Create Web-to-Lead Form**
3. In the field selector, add all the SourceTag custom fields along with your standard fields (Name, Email, etc.)
4. Set the **Return URL** to your thank-you page
5. Click **Generate**

Salesforce produces an HTML form with all the selected fields as visible inputs.


## Step 3: Convert SourceTag fields to hidden inputs

The generated HTML will have all fields as visible text inputs. You need to change the SourceTag fields to hidden inputs.

Find each SourceTag field in the generated HTML and change it from this:

```html
<label for="00NXX000000YYYY">ST First Click Channel</label>
<input id="00NXX000000YYYY" maxlength="255" name="00NXX000000YYYY" size="20" type="text" />
```

To this:

```html
<input id="00NXX000000YYYY" name="00NXX000000YYYY" type="hidden" value="" />
```

The `name` attribute is a Salesforce field ID (looks like `00NXX000000YYYY`). Keep this as-is. Also remove the `<label>` element for each hidden field.

**Important:** SourceTag needs to know which Salesforce field ID maps to which SourceTag field name. Add a `data-st-field` attribute to each hidden input:

```html
<input id="00NXX000000YYYY" name="00NXX000000YYYY" type="hidden" value="" data-st-field="st_fc_channel" />
```

Here is an example of the full set of hidden inputs (replace the Salesforce IDs with your actual IDs from the generated form):

```html
<!-- SourceTag core hidden fields -->
<input name="00NXX000000AAAA" type="hidden" value="" data-st-field="st_fc_channel">
<input name="00NXX000000BBBB" type="hidden" value="" data-st-field="st_fc_detail_1">
<input name="00NXX000000CCCC" type="hidden" value="" data-st-field="st_fc_detail_2">
<input name="00NXX000000DDDD" type="hidden" value="" data-st-field="st_fc_detail_3">
<input name="00NXX000000EEEE" type="hidden" value="" data-st-field="st_fc_detail_4">
<input name="00NXX000000FFFF" type="hidden" value="" data-st-field="st_lc_channel">
<input name="00NXX000000GGGG" type="hidden" value="" data-st-field="st_lc_detail_1">
<input name="00NXX000000HHHH" type="hidden" value="" data-st-field="st_lc_detail_2">
<input name="00NXX000000IIII" type="hidden" value="" data-st-field="st_lc_detail_3">
<input name="00NXX000000JJJJ" type="hidden" value="" data-st-field="st_lc_detail_4">
<input name="00NXX000000KKKK" type="hidden" value="" data-st-field="st_fc_landing_page">
<input name="00NXX000000LLLL" type="hidden" value="" data-st-field="st_lc_landing_page">

<!-- SourceTag optional hidden fields -->
<input name="00NXX000000MMMM" type="hidden" value="" data-st-field="st_fc_click_id">
<input name="00NXX000000NNNN" type="hidden" value="" data-st-field="st_lc_click_id">
<input name="00NXX000000OOOO" type="hidden" value="" data-st-field="st_visits">
<input name="00NXX000000PPPP" type="hidden" value="" data-st-field="st_days_to_convert">
<input name="00NXX000000QQQQ" type="hidden" value="" data-st-field="st_device">
```
## Step 4: Add the form to your website

Paste the modified HTML form onto your website page. The page must also have the SourceTag script installed.

## Step 5: Test

Visit the page with UTM parameters:

```text
?utm_source=test&utm_medium=cpc&utm_campaign=salesforce-test
```

Submit the form. In Salesforce, go to the **Leads** tab and find the test Lead. Check the custom fields. They should contain your attribution data.
## Tips

- Salesforce Web-to-Lead field IDs (like `00NXX000000YYYY`) are unique to your org. Never copy IDs from examples or other orgs.
- The `data-st-field` attribute tells SourceTag which Salesforce field ID corresponds to which SourceTag field. This is needed because Salesforce uses its own field IDs as the `name` attribute rather than the field's API name.
- If you regenerate the Web-to-Lead form, you will get the same field IDs (they do not change). But you will need to convert the fields to hidden inputs again.
- Attribution data on Lead records is preserved when Leads are converted to Contacts and Opportunities, as long as you map the fields during conversion.
- Consider creating a Salesforce report or dashboard that groups Leads by `st_fc_channel` to see which channels drive the most leads.
