Ninja Forms
Ninja Forms is a flexible, free WordPress form builder with a drag-and-drop interface. It renders standard HTML <form> elements in the page DOM, so AttributionHub’s standard forms handler detects and populates it automatically.
Add hidden fields to your form with matching field names, and AttributionHub fills them with attribution data on every page load.
Prerequisites
Before you begin, make sure:
- The AttributionHub tracking script is installed on your site (see Installation)
- You have Ninja Forms installed and activated in WordPress
- You have access to the WordPress admin panel to edit forms
Step 1: Open Your Form
- In your WordPress admin, go to Ninja Forms > Dashboard
- Click on the form you want to edit, or create a new form
Step 2: Add Hidden Fields
- In the Ninja Forms builder, click the + Add new field button (or the + icon at the bottom of the form)
- In the field type list, find and click Hidden (under the “Layout & HTML” or “Miscellaneous” section, depending on your Ninja Forms version)
- Repeat this to add a hidden field for each attribution value you want to capture
Step 3: Configure Each Hidden Field
For each hidden field you added:
- Click on the hidden field in the form editor to open its settings
- Set the Label to something descriptive (e.g., “Attribution Channel - Latest”). This is for your reference only.
- Open the Administration tab (or Advanced settings)
- In the Field Key field, enter the AttributionHub field name (e.g.,
ah_lt_channel)
The Field Key is used as the HTML name attribute on the rendered hidden input. It must exactly match the field name in your AttributionHub field mapping.
Note: In some Ninja Forms versions, the
nameattribute follows a pattern likenf-field-XX. If you cannot change the field key to a custom value, you will need to use thefieldMappingsetting to map AttributionHub paths to Ninja Forms’ field names. See Custom Field Mapping below.
Step 4: Save and Test
- Click Publish (or Save) to save your form
- Visit a page on your site that contains the form
- Open your browser’s DevTools (F12) and inspect the hidden
<input>elements — check that they have attribution values - Submit a test entry
- In WordPress admin, go to Ninja Forms > Submissions and find your test entry. The hidden field values should contain attribution data
For a full testing walkthrough, see Verify It Works.
Recommended Hidden Fields
The table below lists the most commonly used fields. For the complete field catalog, see Field Reference.
Core Attribution Fields (Latest Touch)
| Field Key | Description | Example Values |
|---|---|---|
ah_lt_channel | Channel group (latest touch) | Paid Search, Organic Social, Direct |
ah_lt_source | Traffic source name | Google, Facebook, Direct |
ah_lt_medium | Traffic medium | paid, organic, social, email |
ah_lt_campaign | Campaign name | spring_sale, Organic Search |
ah_lt_content | Content classification | Paid Search Ad, Social Post |
ah_lt_term | Search keyword (if available) | running shoes |
ah_lt_landing_url | Landing page URL (no query string) | https://yoursite.com/pricing |
Core Attribution Fields (First Touch)
| Field Key | Description | Example Values |
|---|---|---|
ah_ft_channel | Channel group (first touch) | Paid Search, Organic Social |
ah_ft_source | Traffic source name | Google, Facebook |
ah_ft_medium | Traffic medium | paid, organic, social |
ah_ft_campaign | Campaign name | launch_campaign |
ah_ft_landing_url | Original landing page URL | https://yoursite.com/blog/post |
Global Fields
| Field Key | Description | Example Values |
|---|---|---|
ah_visitor_id | Unique visitor ID, persistent across visits | a1b2c3d4-e5f6-7890-abcd-ef1234567890 |
ah_touch_count | Total number of recorded visits | 5 |
For additional fields including latest-non-direct touch (
ah_lnd_*), drill-down fields, raw UTM parameters, and ad click IDs, see the full Field Reference.
Custom Field Mapping
If Ninja Forms uses auto-generated field names (like nf-field-1, nf-field-2), map AttributionHub’s internal paths to those names:
<script>
window.attrhub = {
settings: {
fieldMapping: {
"latest.attribution.channelGroup": "nf-field-7",
"latest.attribution.source": "nf-field-8",
"latest.attribution.medium": "nf-field-9",
"latest.attribution.campaign": "nf-field-10",
"latest.attribution.landingPageUrl": "nf-field-11",
"first.attribution.channelGroup": "nf-field-12",
"first.attribution.source": "nf-field-13",
visitorId: "nf-field-14",
},
},
};
</script>Replace the field numbers with the actual values from your form. You can find them by inspecting the rendered form in DevTools.
See Configuration for the full mapping reference.
Tips
- Ninja Forms submissions — All submissions are stored in WordPress. Hidden field values appear in the submission details, making it easy to review attribution data per entry.
- CRM integrations — If you use Ninja Forms’ CRM add-ons (Salesforce, HubSpot, Zoho CRM), map hidden fields to the corresponding CRM fields in the add-on settings.
- Email notifications — Use merge tags like
{field:ah_lt_channel}in your Ninja Forms email notification templates to include attribution values in emails. - Multi-page forms — Add hidden fields to the first page of your form for immediate population on load.
- Zapier / webhook — The Ninja Forms Zapier or Webhooks add-on includes hidden field values in its payload. Connect it to any downstream tool for attribution tracking.
- Conditional logic — Ninja Forms supports conditional logic. While rarely needed for hidden attribution fields, you can conditionally show fields based on attribution values.
Troubleshooting
Hidden fields are empty in submissions
- Inspect the rendered form in DevTools and check the
nameattributes on hidden inputs. Make sure they match your field mapping. - If Ninja Forms uses auto-generated names (like
nf-field-XX), configurefieldMappingto use those names. - Enable logging (
enableLogging: truein settings) and check the browser Console.
Form submission uses AJAX
Ninja Forms submits forms via AJAX by default. AttributionHub’s standard forms handler patches the submit event, and the attribution data is already set in hidden fields before submission occurs, so AJAX submissions work correctly.
Ninja Forms v2 vs v3
Ninja Forms v3 introduced a new form builder and changed field rendering. If you are on v2, the field names and structure may differ. Inspect the rendered HTML in DevTools to identify the correct field name attributes.