Skip to content

Simplify setup, fix tracking bugs and close storefront gaps - #52

Merged
rockwellll merged 4 commits into
mainfrom
simplify-setup
Nov 6, 2026
Merged

rockwellll merged 4 commits into
mainfrom
simplify-setup

Conversation

@rockwellll

@rockwellll rockwellll commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Part of hellotext/hellotext#6270.

Simplifies the plugin's setup, fixes the tracking bugs found while reviewing it, and closes the storefront gaps with the VTEX, Shopify, Magento and Tienda Nube integrations. Three commits, each with passing tests.

Simpler setup

  • The settings page keeps only the Business ID and Access Token. The Webchat, popups, Smart Alert and other widgets are configured in Hellotext; the old webchat options are removed on uninstall.
  • The storefront loads the latest unversioned Hellotext.js from jsDelivr (@hellotext/hellotext/dist/hellotext.min.js), as the other integrations do, and no longer loads it in wp-admin.
  • Another Hellotext environment is set with define('HELLOTEXT_API_URL', …) in wp-config.php instead of APP_ENV.

Bugs fixed

  • Profiles were almost never created. hellotext_create_profile was registered at the bottom of the CreateProfile class file, which only loads when the class is first used. Product views, carts and checkouts never created or linked profiles.
  • Profile and session requests lost /v1 after any earlier request in the same page load, through the client's static suffix.
  • Order events used the shop manager's session. Status changes and refunds sent the admin's hello_session and created a profile for them. They now use the session stored on the order, and users created in wp-admin don't get the admin's session.
  • Orders were missed. order.placed never fired on block themes or when the customer didn't return from the payment page. The session is now captured at classic and block checkout, and order.placed is sent once, when the order is paid or on hold. Orders tracked by earlier versions aren't sent again.
  • Cart events: totals were read before WooCommerce recalculated them, purchased items were later reported as removed, and add to cart from shop pages reported the wrong page. The plugin started a PHP session on every request; the cart snapshot now lives in WC()->session.
  • Coupons with validation errors were tracked as redeemed, and coupons with a minimum spend never were.
  • Connecting: the activation hook was never registered, reconnecting after deactivation was impossible, and changing the Business ID could reconnect with the old token. Deactivating now revokes the WooCommerce API key.
  • Smaller: fatal on orders with deleted products, variations sent without categories or tags, untrimmed tokens, a blocking session request on every page for logged-in shoppers, and generic global function names such as uninstall().

Storefront

assets/storefront.js starts Hellotext.js with the settings in window.hellotextWoo, then:

  • Page sections and the Smart Alert: sets Hellotext.page.section (front page → homepage; shop, categories, tags and attributes → product_collection; product → product_details), so every event and Webchat message reports it, and calls Hellotext.alert.show(section).
  • Push: passes a bundled service worker, the one from the Hellotext.js Push guide, as push.serviceWorkerUrl. It registers under the plugin's folder, so it never replaces a worker the store runs at the root.
  • Webchat "Add to cart": adds the card's product to the WooCommerce cart through ?wc-ajax=add_to_cart, refreshes the mini cart, and credits the resulting cart.added to the card's message.
  • New events: page.viewed in the browser; cart.viewed, and checkout.started once per cart, from PHP.

cart.added carries the product's whole quantity in the cart, since Rails' CartService#add_items_to_cart sets the line to it.

Checkout links and connecting

  • Checkout links: ?hellotext_checkout=1&products=id:quantity,… is the checkout link Hellotext sends stores older than WooCommerce 10.0 (hellotext/hellotext#6959).
    • It replaces the cart with the products and opens the checkout with the link's other parameters, as WooCommerce's /checkout-link/ does.
    • A product that needs options opens its page.
  • Version: the WooCommerce version is sent when connecting, so Hellotext can choose the link.
  • API key: the store's working API key stays until Hellotext accepts the new one. A failed connection shows on the settings page and is retried on the next save.
  • Session links: a customer's session is remembered as linked only after Hellotext links it.
  • Redirects: the Webchat's add to cart opens only pages on the store's own origin.

Testing

  • Pest: 78 tests pass; PHP CS Fixer reports no changes.
  • storefront.js was run in Node against stubbed Hellotext, fetch and jQuery: startup order, page view rules, add to cart, variable products, block Mini-Cart, redirect to cart, failures.
  • The release package was checked to include both assets; CI now checks it too.
  • Not run in a real WordPress/WooCommerce store. The pre-release checklist in DEVELOPMENT.md lists what to smoke test.

Needs a Rails change

Woo::Integration::Create doesn't create a Push channel, as the VTEX and Shopify setup jobs do with find_or_associate_push_channel. Until it does, Api::V1::Public::Push::IdentitiesController rejects subscriptions from Woo stores, so the Smart Alert's "Allow" can't subscribe visitors.

🤖 Generated with Claude Code

rockwellll and others added 3 commits November 6, 2026 19:19
Webchat, popups and other widgets are configured in Hellotext, so the
settings page keeps only the Business ID and Access Token, and the store
loads the latest unversioned Hellotext.js from jsDelivr on the storefront.

- Register hellotext_create_profile from an always-loaded file; it only
  existed after the CreateProfile class autoloaded, so most requests never
  created or linked profiles.
- Send profile and session requests to /v1; the client's static suffix
  dropped it for the rest of the request.
- Use the session stored on the order for status changes and refunds, and
  never link a shop manager's session to a customer or new user.
- Capture the session at classic and block checkout and track order.placed
  once, when the order is paid or on hold, from the thank-you page or the
  status change.
- Compare carts once at shutdown in WC()->session: totals after
  recalculation, changed quantities, no removals after checkout, referer
  URL for background add to cart. Stop starting a PHP session.
- Track only valid coupons, validated against the cart.
- Register the activation hook, reissue the API key on every connection,
  revoke it on deactivation, and move the integration when the Business
  ID changes.
- Handle deleted products and variation terms, trim saved credentials,
  prefix global functions, and replace APP_ENV with HELLOTEXT_API_URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After Hellotext.initialize(), set Hellotext.page.section from the
WooCommerce page (front page: homepage; shop and product taxonomies:
product_collection; product: product_details), so every event and
Webchat message reports it, and call Hellotext.alert.show() for that
section, as the Shopify and VTEX integrations do.

The Smart Alert subscribes visitors to Push, which needs a service worker
on the store's origin. Ship the worker from the Hellotext.js Push guide
in assets/ and pass its path as push.serviceWorkerUrl. It registers under
the plugin's folder, so it never replaces a worker the store runs at the
site root. CI checks the release package includes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…out views

Move the storefront startup into assets/storefront.js, with its settings in
window.hellotextWoo, and close the gaps with the other integrations:

- Add the product of a Webchat card to the WooCommerce cart when Hellotext.js
  dispatches cart.added, through ?wc-ajax=add_to_cart like WooCommerce's own
  buttons, refreshing the mini cart. The card's message is posted along and
  sent as the source of the resulting cart.added.
- Track page.viewed after setting the page section, except on product pages
  and the checkout, which report their own events.
- Track cart.viewed on the cart page and checkout.started on the checkout,
  once per cart and not on the thank-you or payment pages.
- Send the product's whole quantity in cart.added again: Hellotext sets the
  cart line to it.
- Skip the storefront while WooCommerce is inactive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T22:37:23.746885Z 0b1f424 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread assets/storefront.js Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b1f424218

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Events/AppInstalled.php Resolved
Comment thread src/Services/CreateProfile.php Resolved
…merce version

Review findings:
- The Webchat add to cart opens only http(s) pages on the store's origin
  (Aikido: unvalidated window.location navigation).
- A connection keeps the store's working API key until Hellotext accepts
  the new one. A failed connection removes only the new key, shows on the
  settings page, and is retried when the settings are saved again, even
  unchanged. A key a cut-short connection left pending is cleared first.
- A customer's session is remembered as linked only after Hellotext
  linked it, so a failed attempt is retried on the next visit.

Checkout links: ?hellotext_checkout=1&products=id:quantity,..., the link
Hellotext sends stores older than WooCommerce 10.0, replaces the cart with
the products and opens the checkout with the link's other parameters, as
WooCommerce's /checkout-link/ does. A product that needs options opens its
page; when nothing can be added, the cart opens.

The WooCommerce version is sent when connecting, so Hellotext can choose
between WooCommerce's checkout link and the plugin's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rockwellll
rockwellll merged commit 20a7da8 into main Nov 6, 2026
7 checks passed
@rockwellll
rockwellll deleted the simplify-setup branch November 6, 2026 23:29
@rockwellll rockwellll mentioned this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant