<h1 align="center">RescueFill — Abandoned Lead Recovery</h1>

<p align="center">
  <strong>Recover 32% of your lost leads automatically.</strong><br>
  Capture partial form submissions, manage audience lists, run multi-channel campaigns, export data, and connect via webhooks.
</p>

<p align="center">
  <a href="https://wordpress.org/plugins/rescuefill/"><img src="https://img.shields.io/wordpress/plugin/v/rescuefill?label=Version&color=6366f1" alt="Version"></a>
  <a href="https://wordpress.org/plugins/rescuefill/"><img src="https://img.shields.io/wordpress/plugin/wp-version/rescuefill?label=WordPress&color=21a0a0" alt="WordPress"></a>
  <a href="https://www.php.net/"><img src="https://img.shields.io/badge/PHP-8.0%2B-777BB4" alt="PHP"></a>
  <a href="https://www.gnu.org/licenses/gpl-2.0.html"><img src="https://img.shields.io/badge/License-GPLv2-blue" alt="License"></a>
</p>

---

## 🚀 Why RescueFill?

**68% of visitors** who start filling your form never submit it. RescueFill captures their email the moment they type it and gives you a complete toolkit to bring them back.

| Metric | Before RescueFill | After RescueFill |
|--------|-------------------|------------------|
| Form abandonment | 68% | Captured & tracked |
| Lost leads | Invisible | Fully visible |
| Recovery rate | 0% | **Up to 32%** |
| Lead intelligence | None | Country, city, form data |

---

## ✨ Features

### Free Features (All Fully Available)

| Feature | Description |
|---------|-------------|
| 📥 **Smart Form Detection** | Auto-detects CF7, WPForms, Gravity Forms, Ninja Forms, Elementor, Formidable & HTML forms |
| ⚡ **Real-time Capture** | Captures form data as visitors type, before they abandon |
| 📊 **Dashboard** | Real-time stats, recovery rate, status breakdown |
| 📋 **Audience Lists** | Colour-tagged lists with manual assignment |
| 📣 **Broadcast Campaigns** | Send targeted emails via WordPress SMTP |
| 📤 **CSV & JSON Export** | Export with custom field selection and conditions |
| 🔌 **REST API** | Full CRUD for leads, lists, sequences, campaigns, funnels |
| 🔒 **GDPR / CCPA Mode** | Consent-based tracking, IP/location toggle, data retention |
| 🗂️ **Full Lead Management** | Search, filter, paginate, bulk assign, inline actions |
| 🎨 **React Admin UI** | Fast, modern dashboard with dark-mode safe design |

### Pro Addon Features (Optional)

The optional **RescueFill Pro** addon is available at [themefreex.com/rescuefill-pro](https://themefreex.com/rescuefill-pro). It adds:

| Feature | Description |
|---------|-------------|
| 🌍 **IP Geolocation** | Tags each lead with country, region, city via ip-api.com |
| 📧 **Brevo / SendGrid** | Transactional email via Brevo or SendGrid API |
| 🔄 **Multi-Step Sequences** | Automated drip email sequences with visual step editor |
| 🎯 **Drag-Drop Funnel Builder** | Visual automation canvas with React Flow |
| 📧 **Multi-Subsequence Campaigns** | Follow-up steps per campaign with delays & conditions |
| 🔗 **Webhooks** | HMAC-secured outbound webhooks, Zapier/Make/n8n |
| 🌍 **Location Auto-Lists** | Route leads by country/city/region automatically |
| 🧪 **A/B Testing** | Split-test subjects, copy, timing, CTAs |
| 📊 **Advanced Analytics** | Opens, clicks, revenue attribution |

---

## 📦 Installation

### From WordPress.org

1. Go to **Plugins → Add New** in your WordPress admin
2. Search for **"RescueFill"**
3. Click **Install Now** then **Activate**

### Manual Upload

1. Download `rescuefill.zip`
2. Go to **Plugins → Add New → Upload Plugin**
3. Choose the zip file and click **Install Now**
4. Activate the plugin

### Requirements

- WordPress **6.0** or higher
- PHP **8.0** or higher

---

## 🏁 Quick Start

1. Navigate to **RescueFill** in your admin sidebar
2. Configure email settings under **Settings → Email & Providers**
3. The plugin starts tracking form submissions **immediately**
4. Watch leads appear in the **Dashboard**
5. Create an **Audience List** and assign leads
6. Send a **Campaign** to recover abandoned leads

---

## 🔧 How It Works

```
1. Visitor starts filling your form → email captured instantly
2. They close the tab or navigate away
3. RescueFill marks them "abandoned" after your inactivity threshold
4. Send a recovery email (manual or via automated sequence)
5. 32% return and convert → real revenue recovered
```

---

## 📋 Supported Form Plugins

- ✅ Contact Form 7
- ✅ WPForms (Lite & Pro)
- ✅ Gravity Forms
- ✅ Ninja Forms
- ✅ Elementor Forms
- ✅ Formidable Forms
- ✅ Any HTML `<form>` with an email field

---

## 🌐 External Services

This plugin optionally connects to the following third-party services:

### ip-api.com (IP Geolocation)
Used to tag leads with location data (country, city, region).
- **Website:** https://ip-api.com
- **Privacy:** https://ip-api.com/docs/legal
- **Disable:** Settings → Advanced → Disable IP Geolocation

### Brevo (Sendinblue)
Used to send emails via Brevo's transactional API.
- **Website:** https://www.brevo.com
- **Privacy:** https://www.brevo.com/legal/privacypolicy/

### SendGrid
Used to send emails via SendGrid's transactional API.
- **Website:** https://sendgrid.com
- **Privacy:** https://sendgrid.com/policies/privacy/

---

## 🔌 REST API

All endpoints are under `/wp-json/rescue/v1/` and require `manage_options` capability (except `/track`).

| Method | Endpoint | Description |
|--------|----------|-------------|
| `GET` | `/stats` | Dashboard statistics |
| `GET` | `/analytics` | Daily analytics |
| `GET` | `/leads` | List leads (paginated) |
| `POST` | `/leads/bulk-assign` | Bulk assign leads to list |
| `POST` | `/leads/export` | Export leads (CSV/JSON) |
| `GET/POST` | `/lists` | Manage audience lists |
| `GET/POST` | `/sequences` | Manage sequences |
| `GET/POST` | `/campaigns` | Manage campaigns |
| `POST` | `/campaigns/{id}/send` | Send a campaign |
| `GET/POST` | `/funnels` | Manage funnels |
| `POST` | `/track` | Public lead tracking |

---

## 🔒 GDPR / CCPA

- **GDPR Mode** — require explicit consent before tracking
- **Disable IP Tracking** — stop collecting IP addresses
- **Disable Location Tracking** — stop geolocation lookups
- **Data Retention** — auto-purge old leads after configurable days
- **Right to Deletion** — delete individual leads from the admin

---

## 🛠️ Development & Build

### Source Code

This plugin uses modern JavaScript (React) for the admin interface. The source code is publicly available:
- **License:** GPL v2 or later

### Build Instructions

1. **Download the repository:**
   ```bash
   cd rescuefill/rescuefill
   ```

2. **Install dependencies:**
   ```bash
   npm install
   ```

3. **Build for production:**
   ```bash
   npm run build
   ```

4. **Build for development (watch mode):**
   ```bash
   npm run dev
   ```

### Compiled Files

The following files are compiled from source:

| Compiled File | Source | Description |
|---------------|--------|-------------|
| `admin/js/admin.min.js` | `src/` directory | React admin application |
| `admin/css/admin.min.css` | `src/` directory + Tailwind CSS | Admin styles |
| `public/js/tracker.min.js` | `public/js/tracker.js` | Frontend form tracker |

### Development Dependencies

- **React 18** - Admin UI framework
- **React Router** - Client-side routing
- **Tailwind CSS** - Utility-first CSS framework
- **Webpack** - Module bundler
- **Babel** - JavaScript compiler

---

## 📖 Documentation

Full documentation is available at:
- **Online:** [rescuefill.com/docs](https://rescuefill.com/docs)
- **Bundled:** Open `docs/index.html` in the plugin folder

---

## 🗂️ File Structure

```
rescuefill/
├── rescuefill.php          # Main plugin file
├── readme.txt              # WordPress.org readme
├── README.md               # GitHub readme
├── uninstall.php           # Cleanup on uninstall
├── package.json            # NPM dependencies
├── webpack.config.js       # Webpack configuration
├── tailwind.config.js      # Tailwind CSS configuration
├── admin/
│   ├── class-rf-admin.php  # Admin controller
│   ├── css/admin.min.css   # Compiled styles
│   ├── js/admin.min.js     # Compiled React app
│   └── views/admin-root.php
├── includes/
│   ├── class-rf-activator.php
│   ├── class-rf-database.php
│   ├── class-rf-rest.php
│   ├── class-rf-tracker.php
│   ├── class-rf-cron.php
│   ├── class-rf-forms.php
│   ├── class-rf-leads.php
│   ├── class-rf-loader.php
│   ├── class-rf-recovery.php
│   └── class-rf-reminders.php
├── public/
│   ├── class-rf-public.php
│   ├── css/public.css
│   └── js/tracker.js
├── src/                    # React source (development)
│   ├── App.jsx
│   ├── components/
│   ├── hooks/
│   └── utils/
└── docs/
    └── index.html          # Bundled documentation
```

---

## 🔄 Changelog

### 2.1.1 - WordPress.org Compliance Update
- **Fixed:** Inline scripts now use `wp_add_inline_script()` instead of direct `<script>` tags
- **Fixed:** SQL queries use `sanitize_key()` with whitelist validation for column names
- **Fixed:** All prefixes changed from `rf_` (2 chars) to `rescue_` (6 chars) for uniqueness
- **Fixed:** Global variables in uninstall.php use `rescue_` prefix
- **Fixed:** REST API namespace changed from `rf/v1` to `rescue/v1`
- **Fixed:** Script handles updated to `rescue-tracker` and `rescue-admin-app`
- **Fixed:** All options, hooks, filters, and classes use `rescue_`/`RESCUE_` prefix
- **Removed:** Pro addon code completely separated (sold separately on themefreex.com)
- **Added:** Complete source code documentation with GitHub repository link
- **Added:** Build instructions for npm/webpack compilation
- **Tested:** WordPress 7.0 compatibility

### 2.1.0
- **New:** Drag-drop Funnel Builder with React Flow
- **New:** Full webhook engine with HMAC, Zapier/Make/n8n
- **New:** Brevo and SendGrid campaign providers
- **New:** Location-based auto list assignment
- **New:** Multi-subsequence campaign steps
- **New:** Bulk assign leads to list
- **New:** Advanced Export UI with conditions
- **Fixed:** All features fully available without restrictions
- **Fixed:** Script/style handle prefixes updated to `rf-`
- **Fixed:** Proper WordPress enqueue functions used

### 2.0.0
- Major rebuild with React 18 admin UI
- IP Geolocation, Audience Lists, Campaigns, Sequences
- REST API, Export, GDPR mode

### 1.0.0
- Initial release

---

## 🤝 Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Run `npm install && npm run build` in the `rescuefill/` directory
4. Commit your changes
5. Push and open a Pull Request

---

## 📄 License

This project is licensed under the **GPL v2 or later** — see the [LICENSE](https://www.gnu.org/licenses/gpl-2.0.html) file for details.

All source code is available for review, study, and modification in accordance with the GPL license.

---

<p align="center">
  Built with ❤️ by <a href="https://codefreex.com">codefreex</a>
</p>
