Skip to content

[1.12] Channel-aware GTM (backport of #152) - #153

Draft
gabiudrescu wants to merge 3 commits into
stefandoorn:masterfrom
productowner-ro:feature/channel-aware-gtm-1.12
Draft

[1.12] Channel-aware GTM (backport of #152)#153
gabiudrescu wants to merge 3 commits into
stefandoorn:masterfrom
productowner-ro:feature/channel-aware-gtm-1.12

Conversation

@gabiudrescu

Copy link
Copy Markdown

Sylius 1.12 backport of the 2.x proposal in #152 — opening as a parallel draft so the 1.x line isn't left behind. Happy to redirect on shape.

What it does

Same surface as #152: optional gtm.channels.<code> with per-channel id, enabled, and per-feature overrides. Resolved at kernel.request via Sylius's ChannelContextInterface. Existing setups behave identically.

1.x-specific adjustments

  • No Sylius Twig Hooks in 1.x — events template gated inline via a gtm_channel_allows() Twig function; existing Sonata block event listener keeps the template hookable.
  • src/Resources/config/*.yml layout (not config/*.yaml).
  • Listener main-request guard collapsed to a single check that prefers isMainRequest, falls back to isMasterRequest (SF 5.2 → 6.x).
  • CI: PHPStan reportUnmatchedIgnoredErrors: false so the SF6-only isMasterRequest ignore doesn't fail SF5 jobs; vestigial cert/webserver/DB steps marked continue-on-error; --no-security-blocking on composer install (1.12 transitive deps carry advisories already accepted in production shops).

Tests / CI

4/4 matrix jobs green on the fork (PHP 8.0/8.1 × SF ^5.2/^6.0, Sylius ~1.12.0).

Why a separate 1.x PR

Our production shop is on 1.12 and we'd value having this available on both lines. If only the 2.x version (#152) makes sense to you, we'll maintain the fork — no pressure.

cc @lchrusciel (Commerce Weavers) for visibility.

gabiudrescu and others added 3 commits May 27, 2026 19:40
Backport of feature/channel-aware-gtm (Sylius 2.x) to the 1.x line.

- Configuration: optional gtm.channels.<code> with per-channel id,
  enabled toggle, and per-feature overrides
- ChannelFeatureResolver: runtime per-feature gate via ChannelContext
- ChannelGtmListener: kernel.request → setId/enable/disable on the
  GoogleTagManager service for the resolved channel
- Existing listeners (Environment/AddRoute/Context) take resolver as
  optional last constructor arg — BC-safe
- Twig: gtm_channel_allows() function and inline gate on
  events_javascript.html.twig (no Twig Hooks in 1.x — the existing
  Sonata block event listener keeps the template hookable)

Existing setups behave identically — no config change required.

CI: tolerate vestigial cert/webserver/DB steps; add
--no-security-blocking for composer install since 1.12 transitive
deps carry advisories already accepted in production shops.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PHPUnit mock returned false for un-stubbed isMasterRequest() on
Symfony 5.x RequestEvent (where the method still exists), causing
the listeners to bail out early under tests. Prefer isMainRequest
when available and fall back to isMasterRequest otherwise — single
call, single check, behaves correctly across SF 5.2/5.4/6.x.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The isMasterRequest ignore is only needed on Symfony 6 (where the
method is removed); on SF 5 the method exists so the ignore is
unused and the strict reporter fails the build.

Co-Authored-By: Claude Opus 4.7 (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

None yet

Development

Successfully merging this pull request may close these issues.

1 participant