=== ADV.click Lead Ingest ===
Contributors: principiadv
Tags: crm, leads, contact-form-7, wpforms, marketing
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 1.6.9
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Send Contact Form 7 / WPForms leads (including hidden fields) to ADV.click CRM. Optional: send ads-campaign sessions only (not organic visits).

== Description ==

ADV.click Lead Ingest connects a WordPress site to an ADV.click CRM profile. Product page: [adv.click/integrazioni/wordpress](https://www.adv.click/integrazioni/wordpress). After you paste the Ingest URL and secret from **Impostazioni → Ingest API**, the plugin:

* Sends Contact Form 7 and WPForms submissions to `POST /api/v1/ingest/leads`, including hidden fields
* Optional filters: blocked keywords/URLs, ads-only leads, bot/crawler exclusion, phone-click delay
* Keeps a local retry queue if the CRM is unreachable (cron every 15 minutes)
* Attributes later leads with a first-party cookie (30 days) and an IP fallback
* Optionally POSTs **ads-campaign sessions only** (gclid / fbclid / UTM) to `POST /api/v1/ingest/visits` — organic pageviews are not sent to the CRM
* Stores pages locally (table + cookie) for lead attribution even when the CRM visit POST is off
* Optional REST `funnel-by-ip` for chatbot/server lookups (token required)
* Shortcode `[adv_click_calendario]` to embed the booking calendar (iframe) on a WordPress page with slug `calendario`

This is a Software-as-a-Service connector. It only talks to the CRM URL you configure. You need an ADV.click profile (or an agency-managed profile) to use it. ADV.click is a product of Principi S.r.l. (https://www.principiadv.com); this is the official WordPress connector.

**Recommended:** [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) or [WPForms](https://wordpress.org/plugins/wpforms-lite/). Ads-session page lists can be sent without a form plugin; organic visits are never POSTed.

= Privacy =

When the ads-session option is on and a visitor arrives from a paid campaign (gclid / fbclid / UTM), the plugin may send to your CRM: session GUID, landing/last URLs (up to 50 pages), click IDs, browser/device class, and visitor IP. Organic pageviews are not POSTed. Form leads include every submitted field (including hidden ones), plus name, email, phone, and message when present. Phone-click leads send the clicked `tel:` number (not the caller ID).

Admin configuration of URL + secret is the consent to use the ADV.click service (WordPress.org guideline 7, SaaS exception). The `/visits` POST can be disabled on the settings screen; the first-party cookie can still be used only to attribute a later form or tel lead.

Privacy policy: https://www.adv.click/privacy
Data deletion: https://www.adv.click/cancellazione-dati
Support: https://www.adv.click/

== Installation ==

1. Install from this ZIP (Plugins → Add New → Upload) or, once listed, from the WordPress plugin directory.
2. Activate **ADV.click Lead Ingest**.
3. Open Settings → ADV.click Ingest.
4. Paste the Ingest leads URL and secret from your MY portal (Impostazioni → Ingest API).
5. Click **Save**, then **Test connection** (creates a disposable test lead on the CRM).

You may instead define constants in `wp-config.php`:

* `ADV_CLICK_INGEST_URL`
* `ADV_CLICK_INGEST_SECRET`
* `ADV_CLICK_INGEST_VISITS_URL` (optional)

== Frequently Asked Questions ==

= Does the plugin work without ADV.click? =

No. It is a connector. Without a valid CRM URL and secret, leads stay in the local queue.

= Does it send all historical Contact Form 7 entries? =

No. The queue only stores failures that happen after the plugin is installed or upgraded. There is no backfill.

= Does it send all visits to the CRM? =

No. Only ads-campaign sessions (gclid / fbclid / UTM) can be POSTed to `/visits`, and only if **Invia al CRM solo le sessioni da campagna ads** is on. Organic pageviews stay on the site. Form and tel leads still go to the CRM. If you turn the option off, leads stay attributed via the first-party cookie; the `/visits` POST does not run.

= How do I connect the demo / tester profile? =

1. Open https://tester.my.adv.click/
2. Sign in with company identifier `tester` and email `tester@de2.it` (password is the demo profile password, not shipped in this plugin).
3. Go to **Impostazioni → Ingest API**.
4. Paste into this plugin:

* Ingest leads URL: `https://tester.my.adv.click/api/v1/ingest/leads`
* Ingest visits URL: `https://tester.my.adv.click/api/v1/ingest/visits`
* Secret: copy from that MY screen
* Slug CRM: `tester`

5. Save, then **Test connection**. A disposable lead (sorgente `direct`) appears under Leads on the tester profile.

== Changelog ==

= 1.6.9 =
* Shortcode `[adv_click_calendario]` embeds the CRM booking calendar in an iframe (query `cs` / `ls`). Create a WordPress page with slug `calendario`.

= 1.6.8 =
* WordPress.org review: enqueue frontend/admin JS; REST `/track` requires a `wp_rest` nonce; `Tested up to` only in this readme.

= 1.6.7 =
* Form and phone-click leads send sorgente `direct` (or `google_ads` / `social` / `ads` from the session). The CRM select does not accept `wordpress-cf7`.

= 1.6.6 =
* Contact mapping: CF7 slugs `firstname`, `lastname`, `phone`, `company`, `message`, plus type-based email/phone fallback when labels are odd.

= 1.6.5 =
* Settings copy: “Visite paid” now says the CRM receives only ads-campaign sessions (gclid / fbclid / UTM), not all visits. Behavior unchanged (local cookie/table, form/tel leads, paid-only POST /visits).

= 1.6.4 =
* Settings screen: tester/demo howto is no longer a top notice. Same steps sit in a closed “Profilo demo (tester)” accordion at the bottom (also in this FAQ).

= 1.6.3 =
* Text domain and ZIP folder aligned to the wordpress.org slug `adv-click-lead-ingest`. PHP option/function prefixes unchanged.

= 1.6.2 =
* Plugin URI now points at the public product page https://www.adv.click/integrazioni/wordpress (distinct from Author URI).

= 1.6.1 =
* Plugin header: drop Plugin URI (was identical to Author URI; wordpress.org requires them to differ).

= 1.6.0 =
* All form fields (including hidden) sent to the CRM; WPForms support.
* Legacy-parity settings: blocked keywords, bot filter, ads-only, phone delay, funnel-by-ip token, visit table + repair.
* Test mode writes debug lines to PHP error_log (secrets redacted). Does not change the CRM URL.

= 1.5.1 =
* Plugin Check (PCP 2.1.0) clean: wp_rand, late escaping, wp_unslash, Tested up to 7.1.

= 1.5.0 =
* WordPress.org packaging: readme.txt, GPL headers, text domain, uninstall cleanup.
* Optional setting to disable visit POSTs while keeping lead attribution.

= 1.4.0 =
* 30-day session cookie with IP fallback; page list on the lead.

= 1.3.0 =
* Local lead queue and 15-minute retry cron.

= 1.2.0 =
* Connection test lead (`wordpress-plugin-test`).

== Upgrade Notice ==

= 1.6.8 =
Phone-click tracking now sends a WordPress REST nonce. Behavior for forms and visits is unchanged.

= 1.6.7 =
Form leads use CRM sorgente `direct` unless the session already has ads attribution.

= 1.6.6 =
Maps common Contact Form 7 field names (firstname, lastname, phone, company) to CRM contact fields.

= 1.6.5 =
Settings wording only: the plugin does not send organic visits to the CRM. Paid-session POST /visits is unchanged.

= 1.6.4 =
Demo tester instructions on Settings are collapsed by default so client sites are not shown the howto.

= 1.6.3 =
Text domain matches the wordpress.org plugin slug. Existing settings (options) are unchanged.

= 1.6.2 =
Plugin URI restored: public product page on adv.click, different from Author URI.

= 1.6.1 =
Header fix for wordpress.org: Plugin URI removed (it matched Author URI).

= 1.6.0 =
Sends all form fields (including hidden), adds WPForms and filters from the previous ADV CRM plugin. Creates a local visits table on upgrade.

= 1.5.1 =
WordPress.org Plugin Check compliance (escaping, sanitization, Tested up to 7.1).

= 1.5.0 =
Adds a visit-tracking toggle and WordPress.org metadata. Existing sites keep visit tracking on unless you disable it.
