Salesforce Web-to-Lead
Salesforce Web-to-Lead is a built-in Salesforce feature that lets you capture leads from your website and create them directly in Salesforce CRM. It generates an HTML form that you embed on your site, and when a visitor submits the form, a new Lead record is created in Salesforce.
Because Web-to-Lead forms are standard HTML <form> elements, AttributionHub’s standard forms handler detects and populates them automatically. You add hidden fields to the form to capture attribution data alongside the visitor’s name, email, and other information.
Prerequisites
Before you begin, make sure:
- The AttributionHub tracking script is installed on your site (see Installation)
- You have Salesforce access with permissions to create custom fields and generate Web-to-Lead forms
- You have access to your website’s code or CMS to embed the form
Step 1: Create Custom Lead Fields in Salesforce
You need custom fields on the Lead object to store attribution data.
- In Salesforce Setup, go to Object Manager > Lead > Fields & Relationships
- Click New
- For each attribution field:
- Select Text as the data type and click Next
- Set the Field Label to something descriptive (e.g., “Attribution Channel - Latest Touch”)
- Set the Length to 255
- The Field Name (API Name) will be auto-generated (e.g.,
Attribution_Channel_Latest_Touch__c). Note this value — you will use it in the form
- Set the field-level security as needed and click Save
- Repeat for each attribution field
Step 2: Generate the Web-to-Lead Form
- In Salesforce Setup, search for Web-to-Lead in Quick Find
- Click Create Web-to-Lead Form
- Select the fields you want to include:
- Choose your visible fields (Name, Email, Company, etc.)
- Also select each of the custom attribution fields you created in Step 1
- Set the Return URL (the page visitors see after submitting)
- Click Generate
- Copy the generated HTML form code
Step 3: Add Hidden Inputs for Attribution Fields
In the generated form code, find the <input> elements for your attribution fields and change them to type="hidden" so they do not appear on the form:
<form
action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"
method="POST"
>
<!-- Salesforce required fields -->
<input type="hidden" name="oid" value="00DXXXXXXXXXXXXXXX" />
<input type="hidden" name="retURL" value="https://yoursite.com/thank-you" />
<!-- Visible fields -->
<label for="first_name">First Name</label>
<input id="first_name" name="first_name" type="text" />
<label for="last_name">Last Name</label>
<input id="last_name" name="last_name" type="text" />
<label for="email">Email</label>
<input id="email" name="email" type="email" />
<label for="company">Company</label>
<input id="company" name="company" type="text" />
<!-- Attribution hidden fields (custom fields) -->
<input type="hidden" name="00NXXXXXXXXXXXXXXX" />
<!-- Attribution Channel - Latest -->
<input type="hidden" name="00NXXXXXXXXXXXXXXY" />
<!-- Attribution Source - Latest -->
<input type="hidden" name="00NXXXXXXXXXXXXXXZ" />
<!-- Attribution Medium - Latest -->
<input type="hidden" name="00NXXXXXXXXXXXXXXW" />
<!-- Attribution Campaign - Latest -->
<input type="hidden" name="00NXXXXXXXXXXXXXVA" />
<!-- Attribution Landing URL -->
<input type="hidden" name="00NXXXXXXXXXXXXXVB" />
<!-- Attribution Channel - First -->
<input type="hidden" name="00NXXXXXXXXXXXXXVC" />
<!-- Attribution Source - First -->
<input type="hidden" name="00NXXXXXXXXXXXXXVD" />
<!-- Visitor ID -->
<button type="submit">Submit</button>
</form>Note that Salesforce Web-to-Lead uses auto-generated field IDs (like 00NXXXXXXXXXXXXXXX) as the name attribute for custom fields. You will find these IDs in the generated form code.
Step 4: Configure Field Mapping
Because Salesforce uses auto-generated field IDs, you need to map AttributionHub’s internal field paths to these IDs:
<script>
window.attrhub = {
settings: {
fieldMapping: {
"latest.attribution.channelGroup": "00NXXXXXXXXXXXXXXX",
"latest.attribution.source": "00NXXXXXXXXXXXXXXY",
"latest.attribution.medium": "00NXXXXXXXXXXXXXXZ",
"latest.attribution.campaign": "00NXXXXXXXXXXXXXXW",
"latest.attribution.landingPageUrl": "00NXXXXXXXXXXXXXVA",
"first.attribution.channelGroup": "00NXXXXXXXXXXXXXVB",
"first.attribution.source": "00NXXXXXXXXXXXXXVC",
visitorId: "00NXXXXXXXXXXXXXVD",
},
},
};
</script>Replace the 00NXXX... values with the actual field IDs from your generated form code. Each custom field has a unique 18-character Salesforce ID.
See Configuration for the full mapping reference.
Step 5: Test the Integration
- Visit a page on your site that contains the Web-to-Lead form
- Open your browser’s DevTools (F12)
- Inspect the hidden
<input>elements in the form — they should have attribution values populated - Submit a test form entry with a test email address
- In Salesforce, go to the Leads tab and find the test lead. Check the custom fields for attribution values
For a full testing walkthrough, see Verify It Works.
How It Works
Salesforce Web-to-Lead forms are plain HTML forms that POST data directly to Salesforce’s servers. AttributionHub’s standard forms handler:
- Discovers the form on the page (standard
<form>element) - Finds hidden fields whose
nameattributes match the field mapping - Sets the attribution values
- When the visitor submits, the form data (including attribution values) is sent to Salesforce, which creates a new Lead record with all the fields populated
Recommended Fields
The table below lists the most commonly used fields. For the complete field catalog, see Field Reference.
Core Attribution Fields (Latest Touch)
| Description | Example Values |
|---|---|
| Channel group (latest touch) | Paid Search, Organic Social, Direct |
| Traffic source name | Google, Facebook, Direct |
| Traffic medium | paid, organic, social, email |
| Campaign name | spring_sale, Organic Search |
| Landing page URL (no query string) | https://yoursite.com/pricing |
Core Attribution Fields (First Touch)
| Description | Example Values |
|---|---|
| Channel group (first touch) | Paid Search, Organic Social |
| Traffic source name | Google, Facebook |
| Campaign name | launch_campaign |
Global Fields
| Description | Example Values |
|---|---|
| Unique visitor ID, persistent across visits | a1b2c3d4-e5f6-7890-abcd-ef1234567890 |
For additional fields, see the full Field Reference.
Tips
- Lead assignment rules — Use attribution field values in Salesforce lead assignment rules to route leads to the right sales team based on their traffic source.
- Reports and dashboards — Create Salesforce reports grouping leads by attribution channel, source, or campaign. Build dashboards to visualize which marketing channels generate the most leads.
- Salesforce Campaigns — Consider linking attribution data to Salesforce Campaigns for multi-touch attribution analysis within Salesforce’s Campaign Influence feature.
- Lightning Record Pages — Add your attribution custom fields to the Lead Lightning Record Page layout so sales reps can see how each lead found your website.
- Web-to-Case — The same approach works for Salesforce Web-to-Case forms. Create custom Case fields, add them as hidden inputs, and configure the field mapping.
- Validation rules — Do not create Salesforce validation rules that require attribution fields to be non-empty, as some visitors may have limited attribution data (e.g., direct visits).
Troubleshooting
Custom fields are empty on the Lead record
- Verify the field IDs (
00NXXX...) in your form match the actual custom field IDs in Salesforce. You can find the correct IDs by regenerating the Web-to-Lead form. - Confirm the
fieldMappingin your settings maps AttributionHub paths to the correct Salesforce field IDs. - Inspect the hidden
<input>values in DevTools before submitting. - Enable logging (
enableLogging: truein settings) and check the browser Console.
Form submits but no Lead is created
This is a Salesforce issue. Common causes include: missing required fields, inactive Web-to-Lead feature, or validation rule failures. Check Salesforce Setup > Web-to-Lead to verify it is enabled and check the debug logs.
Field IDs are hard to read
Salesforce’s auto-generated field IDs (like 00NXXXXXXXXXXXXXXX) are not human-readable. Add comments in your HTML next to each hidden field to document which attribution value it captures:
<input type="hidden" name="00NXXXXXXXXXXXXXXX" />
<!-- ah_lt_channel -->
<input type="hidden" name="00NXXXXXXXXXXXXXXY" />
<!-- ah_lt_source -->This makes maintenance easier for anyone editing the form later.