Skip to content

Skip statistics tracking for bots - #42

Open
LameuleFR wants to merge 1 commit into
PrestaShop:devfrom
LameuleFR:perf/skip-guest-for-bots
Open

LameuleFR wants to merge 1 commit into
PrestaShop:devfrom
LameuleFR:perf/skip-guest-for-bots

Conversation

@LameuleFR

@LameuleFR LameuleFR commented Oct 21, 2026 •

Copy link
Copy Markdown
Questions Answers
Description? Do nothing in displayBeforeBodyClosingTag for bots (Connection::isBot(), the same check core uses to skip ps_connections). Bots send no cookie, so each hit created a ps_guest row nobody references, incremented the page view counter, and with "Save page views for each customer" on wrote a ps_connections_page row with id_connections = 0. Bots also no longer get the module's scripts (plugin detection, page time). The method_exists guard keeps the module working on PrestaShop versions without Connection::isBot() (before 8.0), where the behaviour is unchanged; the PHPStan 1.7.x configs ignore the call accordingly.
Type? improvement
BC breaks? no
Deprecations? no
Fixed ticket? N/A
How to test? Request the front office without cookie as a bot (curl -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" <shop>/), with default settings then with the three options enabled: no new row in ps_guest or ps_connections_page, and the ps_page_viewed counter is not incremented. With a browser user agent, first visit and revisit behave as before (rows in ps_guest, ps_connections, ps_connections_source, ps_connections_page if enabled). Related core PR: PrestaShop/PrestaShop#43285.

Measured on PrestaShop develop (9.x), home page, 20 hits per bot (Googlebot, bingbot, AhrefsBot), no cookie, before → after:

Settings Rows written per 20 hits Queries per hit
Default ps_guest +20 → 0 (−100%) 299 → 298 (−0.3%)
The 3 options on ps_guest +20, ps_connections_page +4, page view counter → 0 (−100%) 304 → 298 (−2%)
Browser first visit / revisit unchanged unchanged
  • No more orphan rows: 100k bot hits per day added 100k ps_guest rows per day, linked to no connection, cart or customer (about 20 MB per day, 7 GB per year with indexes).
  • Identical output for browsers: normalized HTML of 7 pages has the same hash before and after for a browser first visit and revisit; for bots, only the plugin detection and page time scripts are gone (options on).
  • Bot detection follows core: which user agents are skipped depends on the core version's Connection::isBot() list (bingbot and AhrefsBot are recognised since 9.2.0; before 8.0 nothing changes). Its false positives now also lose the guest row and the page view, in addition to the connection they already lost (e.g. Motorola in-app and WeChat browsers on 8.0 to 9.2, fixed in develop). Behaviour change to be aware of: with "Save global page views" on, bot hits are no longer counted, which matches core not recording bot connections.

@LameuleFR
LameuleFR force-pushed the perf/skip-guest-for-bots branch from eb5e895 to bcd2367 Compare October 21, 2026 14:08
@LameuleFR LameuleFR changed the title Fix: Skip statistics tracking for bots Skip statistics tracking for bots Oct 21, 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.

4 participants