Skip to content

Avoided setting the llms-tracking cookie when there are no events to track#2331

Merged
ideadude merged 1 commit into
gocodebox:devfrom
eri-trabiccolo:issue/2330
Feb 14, 2023
Merged

Avoided setting the llms-tracking cookie when there are no events to track#2331
ideadude merged 1 commit into
gocodebox:devfrom
eri-trabiccolo:issue/2330

Conversation

@eri-trabiccolo

@eri-trabiccolo eri-trabiccolo commented Jan 23, 2023

Copy link
Copy Markdown
Contributor

Description

Fixes #2330
Going to set the llms-tracking cooking as soon as an events needs to be tracked.

How has this been tested?

manually with the Advanced Videos add-on.

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been tested.
  • My code passes all existing automated tests.
  • My code follows the LifterLMS Coding & Documentation Standards.

@eri-trabiccolo eri-trabiccolo marked this pull request as ready for review January 23, 2023 11:27
@eri-trabiccolo eri-trabiccolo requested a review from a team January 23, 2023 11:27
@eri-trabiccolo eri-trabiccolo self-assigned this Jan 23, 2023
@ideadude ideadude merged commit e7c6665 into gocodebox:dev Feb 14, 2023
brianhogg pushed a commit that referenced this pull request Jun 22, 2026
…age views stay cacheable (#3211)

* Defer session cookie until session data is written

LifterLMS emitted the wp_llms_session_<COOKIEHASH> cookie on the first
page view of every anonymous visitor, even on pages that never touch the
session. Full-page caches won't store responses carrying a Set-Cookie
header, so this disabled anonymous page caching site-wide whenever
LifterLMS was active.

Make the session cookie lazy: a brand-new session lives in memory only
(no Set-Cookie, no DB row) until the first write via LLMS_Session::set(),
at which point the cookie is emitted. Anonymous visitors who never write
session data never receive the cookie, so those responses stay
cache-eligible. Mirrors the llms-tracking cookie approach from #2330 / #2331.

Fixes #3210

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Emit the deferred session cookie unconditionally on first write

The headers_sent() guard around the deferred set_cookie() call dropped the
cookie whenever output had already started, which broke the new behavior
under PHPUnit (and would have failed in CI). The eager cookie was
previously emitted from the constructor with no such guard, and every
first-party session write runs before output, so emit unconditionally to
match that behavior and keep it testable.

Seed a cookie in the existing-cookie session tests that previously relied
on the constructor eagerly creating one.

Verified locally: tests-run --group sessions,coupons -> 65 tests, 452 assertions, OK.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants