Repository navigation
Consent API, checkout_started, ecommerce-spec properties, PHP error filter (0.10.0) - #3
Merged
Merged
Conversation
…ilter (0.10.0) - WP Consent API: posthog-js runs cookieless with replay off until the visitor gives statistics consent, decided in the browser so cached pages work. New "Wait for cookie consent" setting, on by default. - checkout_started fires once per cart at the first checkout view; checkout_viewed is unchanged. - Ecommerce-spec properties (category, price, value, revenue, shipping, tax, discount, coupon, products) on product, cart and order events. - ErrorFilter in front of posthog-php's error handler drops notices, deprecations and the parse_str nesting warning from PostHog. - Sanitize forwarded IP headers (fixes PHPCS on main). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When "Wait for cookie consent" is on, Identity no longer reads the ph_<key>_posthog cookie unless the WP Consent API (or, without it, an explicit allow cookie) grants the statistics category. A cookie left over from before consent was required is not read, so server and browser events don't split one visitor. Order events are unaffected: they use the WooCommerce session id or the id saved on the order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shop runs without a consent banner, so 0.10.0 keeps today's behaviour by default: cookies, session replay and cookie-stitched server events for anonymous visitors. The Consent API support stays behind the setting, and Tagbridge only registers with the Consent API when the setting is on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A PostHog review of chinesecleavers.co.uk found four problems:
checkout_startedhadn't fired since 0.9.0, when it was renamed toorder_placed, so the funnel insights went stale.$exceptionevents a month were benign PHP warnings.What changed
persistence: 'memory'and replay off. No PostHog cookie or localStorage is written.statisticsconsent: switches tolocalStorage+cookieand starts replay (if replay is enabled).wp_listen_for_consent_changeandwp_has_consent(), so LiteSpeed-cached HTML stays correct.wp_consent_api_registered_*, only while the setting is on) and describes the cookie (wp_add_cookie_info).Consent::may_read_posthog_cookie()), so a cookie left over from before consent was required isn't used.checkout_started(spec: Checkout Started) fires once per cart, at the first checkout view, deduplicated by cart hash in the WooCommerce session.checkout_viewedstill fires on every load; four insights use it.category/priceon product events, plusprice/valueon add to cart.value,revenue,shipping,tax,discount,coupon,currencyand aproducts[]list on cart_viewed, checkout_viewed, checkout_started, order_placed and order_completed.category/price/value/couponon product_purchased, andcouponon coupon_applied.valuestill means the order total, so revenue insights keep their meaning.Core/Events/ErrorFilterwraps its error handler.parse_str()nesting warning. They still go to PHP's normal log.tagbridge_posthog_ignored_php_errorsandtagbridge_posthog_ignored_php_error_levels.mainred.v0.10.0tag is pushed.Event names
Existing snake_case names are kept, and
checkout_startedis added to match the spec. Renamingproduct_added_to_cart→product_addedandproduct_removed_from_cart→product_removedwould break the live dashboard, so that is left to the owner.Behaviour on upgrade
Nothing changes for visitors on upgrade: the owner chose not to use a consent banner, so consent gating is off by default. The site keeps setting cookies and running replay and autocapture with no consent prompt. That is the UK PECR/GDPR risk the review flagged, and it is now the owner's choice.
If the setting is turned on later without a Consent API banner, every visitor stays cookieless. Measured over the last 30 days, the PostHog cookie was the only id for 964 of 1,149
product_viewedevents, and those server events would mostly stop. So install a banner first.Tests
composer test:unit: 64 tests pass. New tests:ErrorFilterTest,ConsentTest(including the off-by-default check), andConsentSnippetTest, which runs the generated snippet in Node against a fake posthog.SchemaTestupdated.composer lintis clean.🤖 Generated with Claude Code