# Form Referral Capture Audit

**Last Updated:** 2026-03-17

Audit results and remediation log for Ordio Loop affiliate/referral tracking across all forms.

## Summary

The Ordio Loop partner program uses two attribution mechanisms:

1. **`affiliate` param** (Ordio Loop) → `affiliate_partner_id` in HubSpot – for commission tracking (e.g. `?affiliate=AP-20260129-ABC123`)
2. **`partner` param** (legacy) → `partner__c` enum in HubSpot – for partner landing pages (e.g. `?partner=gastroberatung`)

**Important:** HubSpot Forms API v3 requires fields to be on the form definition for submissions to accept them. `partner__c` and `affiliate_partner_id` are different properties; both can exist on a form.

## HubSpot Forms API Audit (2026-03-17)

Audit script: `php v2/scripts/hubspot/audit-forms-affiliate-fields.php [--verbose]`

**Status: All 13 forms complete.**

| Form | GUID | affiliate_partner_id | affiliate_referral_date | partner__c |
|------|------|----------------------|-------------------------|------------|
| Main Lead Capture / Demo Form | 9b93ee13-fad2-4ce8-8ea2-4e588932af2a | ✓ | ✓ | — |
| Lead Capture Popup | 9f9d4e35-d8d9-4283-93b6-1a789e0a1281 | ✓ | ✓ | — |
| Tools / Workdays | a91b263c-7ca2-418b-b35c-9664c30e968b | ✓ | ✓ | ✓ |
| Template Download | 11e392f7-aece-4969-8c39-402ee6cb2330 | ✓ | ✓ | ✓ |
| Add-on / Excel | c2022eda-c9b4-4010-a02d-d920852585b1 | ✓ | ✓ | ✓ |
| ShiftOps Report | 41d07332-6697-4daa-b27e-dd60515f9c0f | ✓ | ✓ | ✓ |
| ShiftOps NPS | 804459f7-c18d-4da6-8a0b-a81f44bb8275 | ✓ | ✓ | — |
| Gated Content / Webinar / Event | c74e1237-6b52-4a16-bac7-daaf98881e63 | ✓ | ✓ | — |
| Hero Email Form | c1d24914-f2a2-4371-b12a-7217553f5897 | ✓ | ✓ | — |
| Cello Referral | a47cfeb7-4d00-4a76-971d-23a82739fb15 | ✓ | ✓ | ✓ |
| Event Lead Capture | e9d5fd47-6772-4c0a-943b-8f726afd8e4b | ✓ | ✓ | — |
| Kostenlos Testen | 59a2ae2a-87d2-424b-a911-dda4b42e73a4 | ✓ | ✓ | ✓ |
| SDR Form (HubSpot Embedded) | ad1036ce-33ec-463b-adde-2fa546324c8a | ✓ | ✓ | — |

**partner__c** = legacy partner landing pages (optional for most forms). **affiliate_partner_id** + **affiliate_referral_date** = Ordio Loop commission tracking (required).

### Scripts

- **Audit:** `php v2/scripts/hubspot/audit-forms-affiliate-fields.php [--json] [--verbose]`
- **Add affiliate_partner_id:** `php v2/scripts/hubspot/add-affiliate-field-to-forms.php [--dry-run] [--form=GUID]`
- **Add affiliate_referral_date:** `php v2/scripts/hubspot/add-affiliate-referral-date-to-forms.php [--dry-run] [--form=GUID]`

## Remediation Completed (2026-03-17)

### Phase 1: Form Handler and Include Fixes

- **include_form-hs.php:** Added `affiliate_modal` hidden field; `populateUTMFields()` populates from `utmData.affiliate`
- **form-hs.php:** Extracts affiliate from POST, cookie, page_url; sends `affiliate_partner_id` and `affiliate_referral_date` to HubSpot
- **utm-tracking.js:** `addUTMToForm()` adds `partner_modal` and `affiliate_modal` to hubspotFields

### Phase 2: API Endpoint Fixes

- **submit-template.php:** Extracts affiliate; sends to HubSpot
- **addon-request.php:** Extracts affiliate; sends to HubSpot
- **export-workdays.php:** Extracts affiliate; adds to utmData; `addToHubSpot()` sends to HubSpot
- **shiftops-hubspot.php:** Extracts affiliate; adds to hubspotFields
- **include_email_form.php:** Gets affiliate from utmTracker/cookie; adds `affiliate_partner_id` and `affiliate_referral_date` to HubSpot payload

### Phase 3: HubSpot API Audit

- **verify-affiliate-setup.php:** All checks pass (affiliate_partner_id, affiliate_referral_date on contacts and deals)

### Phase 4: Gated Content, Webinar, SDR

- **Gated content / Webinar:** Use form-hs; Phase 1 fixes apply via addUTMToForm
- **include_form-hubspot-sdr.php:** Added `getAffiliateParameter()`; injects `affiliate_partner_id` and `affiliate_referral_date` via setFormValues and fetch/XHR interception

### Phase 5: Tracking and Cookie Verification

- **utm-tracking.js:** Extracts `affiliate` from URL; sets 30-day cookie; `getUTMDataForAPI()` returns affiliate
- **Redirects:** .htaccess uses QSA on redirects to preserve UTM and affiliate params

### Phase 6: Testing

- **test-ordio-loop-attribution.php:** Created; validates extraction logic and endpoint includes

## Form Coverage Matrix

| Form/Endpoint | affiliate_partner_id | partner__c |
|---------------|----------------------|------------|
| form-hs.php | ✓ | ✓ |
| collect-lead.php | ✓ | ✓ |
| lead-capture.php | ✓ | — |
| submit-template.php | ✓ | ✓ |
| addon-request.php | ✓ | ✓ |
| export-workdays.php | ✓ | — |
| shiftops-hubspot.php | ✓ | — |
| include_email_form.php | ✓ | ✓ |
| include_form-hubspot-sdr.php | ✓ | — |

## Demo Booking / Orbianca Redirect

form-hs.php redirects SDR form submissions to Orbianca. As of 2026-03-17, the redirect URL includes `affiliate` and UTM params when present via `buildOrbiancaRedirectUrl()`.

## HubSpot SDR Form Configuration

The HubSpot embedded SDR form injects `affiliate_partner_id` via JavaScript. **Completed 2026-03-17:** `affiliate_partner_id` added as a hidden Contact property on the SDR form in HubSpot (Settings → Forms → Edit SDR form → Add field → Contact property: affiliate_partner_id → Make this field hidden).

## Related Documentation

- [PARTNER_UTM_AND_ATTRIBUTION.md](PARTNER_UTM_AND_ATTRIBUTION.md) – UTM and attribution overview
- [.cursor/rules/ordio-loop-forms.mdc](../../.cursor/rules/ordio-loop-forms.mdc) – Cursor rule for new forms
