=== Feedbeam ===
Contributors: ghaithj
Tags: openai ads, chatgpt ads, conversion tracking, lead tracking, product feed
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 2.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Track leads, sign-ups and sales with the OpenAI Ads pixel on any WordPress site. With WooCommerce, also put your catalog in ChatGPT ads.

== Description ==

Feedbeam connects your WordPress site to OpenAI Ads, the ads that run inside ChatGPT.

1. **Measurement pixel, on any WordPress site.** Loads the OpenAI Ads pixel and reports page views, leads from your forms and newsletter signups, and account registrations, so lead campaigns can optimize on real conversions. No store needed.
2. **With WooCommerce: shopping events and product feed.** Adds product views, add to cart, checkout and purchases, and builds the product feed OpenAI Ads Manager reads for product feed campaigns, served at a private link you paste into Ads Manager under "Connect your feed via URL".

Feedbeam detects WooCommerce by itself: the store features appear when WooCommerce is active and stay out of the way when it is not. Everything is set up from **Settings › Feedbeam** (or **Marketing › Feedbeam** on a WooCommerce store). No code needed.

= Product feed (WooCommerce) =

* **Private feed link** for Ads Manager: `https://your-site/openai-feed/<token>/products.csv`. A plain path with no query string, with optional HTTP Basic authentication, gzip compression and a one-click "replace link".
* **Always fresh:** rebuilt hourly, twice daily or daily. OpenAI expires items that are not refreshed for two weeks; if a scheduled rebuild is missed, the next fetch triggers one.
* **37 columns** in OpenAI's format: title, description, price, sale price, availability, images, GTIN, MPN, brand, category, size and weight, reviews, seller and policy links, target countries and eligibility flags.
* **Variations** become one row each, grouped under their parent with their color, size and other options.
* **Prices match the page:** your tax display setting and currency decimals are followed.
* **Clean data:** invalid GTINs are left out instead of sent, units are converted to OpenAI's values, and rows missing a required field are reported.
* **Products tab** with quality badges (no image, image not JPEG/PNG, no price, no description, out of stock) and include / exclude per product or in bulk.
* **Per-product settings:** exclude from the feed, checkout eligibility, GTIN and MPN.
* **Test feed URL** button and "last fetched" time, so you know Ads Manager can read the feed.

= Conversion tracking =

On any WordPress site:

* **page_viewed** on every page.
* **lead_created** when a visitor successfully submits a form or newsletter signup.
* **registration_completed** when a visitor creates an account (wp-login, or My Account and checkout on a store).

With WooCommerce:

* **contents_viewed** on product pages.
* **items_added** for AJAX and classic add to cart.
* **checkout_started** on classic and block checkout.
* **order_created** once per order, with items and totals, even if the thank-you page is refreshed.

And everywhere:

* **Direct or Google Tag Manager** loading, a toggle per event and a debug mode.

= Lead sources =

Contact Form 7, WPForms, Gravity Forms, Elementor Pro forms, Fluent Forms, Formidable Forms, Ninja Forms, MC4WP (Mailchimp for WordPress) and MailPoet. Each can be switched on or off. Only successful submissions count; invalid and spam submissions are ignored. Any other tool can send a lead with one line of PHP or JavaScript.

= Feedbeam Pro =

The Pro add-on adds Klaviyo lead tracking (signup forms on any site, checkout opt-ins on a store), and for WooCommerce stores multiple filtered feeds (by category, tag, stock or price, each with its own link) and SFTP upload. The free plugin is complete on its own and does not lock any feature.

= Built-in documentation =

The Documentation tab has a live "Your setup" checklist that reads your settings and shows what is ready and what is missing, plus guides for every setting, event and feed column, troubleshooting and developer hooks.

== External services ==

This plugin connects to OpenAI Ads, a service provided by OpenAI, L.L.C., when you enter an OpenAI Ads Pixel ID.

* **OpenAI Ads pixel.** In "Direct" mode, every front-end page loads OpenAI's pixel script from `https://bzrcdn.openai.com/sdk/oaiq.min.js`. In "Google Tag Manager" mode the plugin does not load it; your own GTM container does. The pixel sends OpenAI the events listed above: the page address, product IDs, names, quantities, prices and order totals, and, for leads and registrations, only the event name and a random ID (no form contents, names or email addresses). The pixel may set its own cookies in the visitor's browser. Nothing is sent until you enter a Pixel ID.
* **Product feed.** OpenAI Ads Manager downloads your feed from your site when you connect it by URL. The feed contains public product information only. The plugin does not send the feed anywhere by itself.

OpenAI terms of use: https://openai.com/policies/terms-of-use/
OpenAI privacy policy: https://openai.com/policies/privacy-policy/

Mention the OpenAI Ads pixel in your privacy policy and cookie banner as your local law requires.

== Installation ==

1. Install and activate the plugin from **Plugins › Add New**, or upload the zip under **Plugins › Add New › Upload Plugin**.
2. Go to **Settings › Feedbeam**, or **Marketing › Feedbeam** when WooCommerce is active.
3. **Pixel tab:** enter your Pixel ID (found in OpenAI Ads Manager under Measurement), choose Direct or Google Tag Manager loading, pick the events and lead sources, and save.
4. Turn on Debug mode, submit a form (or place a test order on a store) and watch the browser console, then turn Debug mode off.

On a WooCommerce store, also connect the product feed:

1. **Product feed tab:** check the brand, seller name, countries and policy links, and save.
2. Copy the **File URL** (and the username and password if Basic authentication is on). In OpenAI Ads Manager, open Feeds, choose **Connect your feed via URL**, paste it, review the sample and set the import schedule.

== Frequently Asked Questions ==

= Do I need WooCommerce? =

No. Without WooCommerce, Feedbeam tracks page views, leads and account sign-ups on any WordPress site, which is all a lead generation site needs. Install WooCommerce later and the shopping events, product feed and Products tab appear on their own, with nothing to reinstall.

= Do I need an OpenAI Ads account? =

Yes. You need an OpenAI Ads Manager account to create product feed campaigns and to get a Pixel ID.

= Is my product feed public? =

No. The feed lives at a link with a long secret token. You can also require a username and password, and replace the link at any time. The feed files are stored under random names that cannot be guessed.

= I already load the OpenAI pixel with Google Tag Manager. Will this conflict? =

Not if the pixel is loaded from one place only. Choose the Google Tag Manager mode: Feedbeam then adds no pixel code and sends its events through the pixel your GTM container loads. Your GTM tag must load the pixel and call init. Then, for each event Feedbeam sends (for example lead_created), pause the GTM tag that sends the same event, or each conversion is counted twice.

= Are amounts sent in the right format? =

Yes. The pixel expects integers in the currency's smallest unit ($12.99 becomes 1299). Zero-decimal currencies such as JPY are handled.

= Can I keep products out of my ads? =

Yes. Exclude them from the Products tab or from the product's edit screen. They stay in the feed marked as not eligible, so OpenAI removes them cleanly.

= My form plugin is not listed. Can I still track leads? =

Yes. Call `do_action( 'woai_track_lead', 'my-form' )` in PHP after a successful submission, or `woaiTrack( 'lead_created' )` in JavaScript.

= I used the "WooCommerce OpenAI Ads" plugin. How do I switch? =

Install and activate Feedbeam, then deactivate and delete "WooCommerce OpenAI Ads". Feedbeam is the same plugin under a new name: it keeps all settings, and the feed link already connected in Ads Manager keeps working. Deleting the old plugin does not remove its data, which is how Feedbeam picks it up.

= What is removed when I delete Feedbeam? =

Nothing, unless you turn on "Delete all Feedbeam data when the plugin is deleted" on the Pixel tab, under Uninstall. With it on, deleting Feedbeam removes its settings, feed files, feed link, scheduled tasks and the per-product fields (GTIN, MPN, exclusions). Deactivating never removes anything.

== Screenshots ==

1. Product feed tab: defaults, private feed link and rebuild schedule.
2. Products tab with quality badges and include / exclude.
3. Pixel tab: loading mode, events and lead sources.
4. Documentation tab with the live setup checklist.

== Changelog ==

= 2.0.1 =
* Fixed: in Google Tag Manager mode, events could stay stuck and never reach OpenAI. Feedbeam created the pixel queue before GTM ran, so OpenAI's GTM code thought the pixel was already loading and never loaded it. Feedbeam now adds no pixel code in this mode, and its events wait for your GTM tag with no time limit.
* Direct mode does not load the pixel script a second time if another tag already added it.
* Gravity Forms: AJAX confirmations also trigger the lead.
* A lead waiting for the pixel is kept until the next page if the visitor leaves first.
* Clearer guidance: load the pixel from Direct or GTM, never both, and do not send the same event from Feedbeam and GTM.

= 2.0.0 =
* Renamed from "WooCommerce OpenAI Ads" to Feedbeam (WordPress.org slug: feedbeam).
* WooCommerce is now optional: page views, leads and registrations work on any WordPress site, and the shopping events and product feed turn on when WooCommerce is active. Without WooCommerce the settings are under Settings › Feedbeam. Settings and the feed link carry over.
* SFTP upload and Klaviyo lead tracking are now in the separate Feedbeam Pro add-on.
* New: hooks for add-ons (extra feeds, lead sources, settings tabs, documentation sections).
* The pixel tag is now printed through WordPress's script functions.
* Coding standards and security hardening (input sanitizing, escaping, translator comments).
* New: optional clean uninstall ("Delete all Feedbeam data when the plugin is deleted", off by default).
* Feed cells that start with = + - or @ get a leading apostrophe, so they cannot run as formulas when the CSV is opened in a spreadsheet.

= 1.5.0 =
* Klaviyo checkout opt-ins and the legacy Klaviyo signup widget count as leads.
* Lead sources added in a new version start switched on.

= 1.4.1 =
* Security: feed files use random, unguessable names. Old fixed-name files are deleted on update.

= 1.4.0 =
* New: Documentation tab with a live setup checklist.
* Fix: contents_viewed fired only for the first product in a session; variations no longer copy the parent GTIN.

= 1.3.0 =
* New: page_viewed, lead_created (9 form plugins) and registration_completed events.

= 1.2.0 =
* New: private feed URL for Ads Manager, rebuild schedule, is_ads_eligible, reviews, native GTIN, woai_feed_row filter.
* Many feed accuracy fixes (variation IDs, backorder, prices, units, GTIN validation).

= 1.1.0 =
* New: product feed, Products tab, per-product settings, feed defaults.

= 1.0.0 =
* Initial release: Direct and GTM loading, add to cart, checkout and purchase events.

== Upgrade Notice ==

= 2.0.1 =
Fixes events not reaching OpenAI in Google Tag Manager mode when GTM uses OpenAI's base code. Recommended for everyone using GTM mode.

= 2.0.0 =
The plugin is now called Feedbeam. If you used "WooCommerce OpenAI Ads", deactivate and delete it after activating Feedbeam; settings and the feed link carry over. SFTP upload and Klaviyo tracking are now in Feedbeam Pro.
