Channel-aware GTM container resolution (draft, addresses #151) - #152
Channel-aware GTM container resolution (draft, addresses #151)#152gabiudrescu wants to merge 1 commit into
Conversation
|
Can we move the CI changes into a separate PR? Also, as Behat is removed here, I don't think we need the scenario's. I'm happy to not re-introduce them actually, I find it generally painful to maintain :) |
stefandoorn
left a comment
There was a problem hiding this comment.
All relatively small stuff I believe :)
| - "@sylius.context.channel" | ||
| - "@sylius.context.locale" | ||
| - "@sylius.context.currency" | ||
| - "@GtmPlugin\\Resolver\\ChannelFeatureResolver" |
There was a problem hiding this comment.
We aren't doing any services here by just class name I believe, can we keep that in line with existing patterns?
There was a problem hiding this comment.
(this applies at multiple locations)
| @@ -0,0 +1,10 @@ | |||
| services: | |||
|
|
|||
There was a problem hiding this comment.
(this applies at multiple locations)
| * | ||
| * @return array<string, array{id: ?string, enabled: bool, features: array<string, bool>}> | ||
| */ | ||
| private function normaliseChannels(array $channels): array |
There was a problem hiding this comment.
I believe this can be written different, still performant, in a way more readable way so for future maintenance it's easier to grasp. Rule of thumb is that if I need to look at it longer than 3 seconds to see what all these ?? etc. do, it's too complex ;-)
| public function __construct( | ||
| private readonly bool $enabled, | ||
| private readonly GoogleTagManagerInterface $googleTagManager, | ||
| private readonly ?ChannelFeatureResolver $featureResolver = null, |
There was a problem hiding this comment.
Can we add a deprecation immediately that on the next major version this will be made required?
There was a problem hiding this comment.
(applies to multiple locations & then the bool $enabled will also change probably)
| } | ||
|
|
||
| /** @param array{id: ?string, enabled: bool} $config */ | ||
| private function apply(array $config): void |
There was a problem hiding this comment.
I think this can move into the onKernelRequest method, as it's only a single time call
| $global = $this->globalFeatures[$feature] ?? false; | ||
|
|
||
| try { | ||
| $code = $this->channelContext->getChannel()->getCode(); |
There was a problem hiding this comment.
Can we return here if the code can be found? So within the try, and then only have the global return as exceptional state.
|
Did CI run? Normally I need to enable it again, but I don't see that today. Also please squash the PR into a single commit with a clear commit message, this PR is now 6 commits of which the first 5 then (I assume) break things :) |
a802e43 to
cc9c616
Compare
|
@stefandoorn wdyt? Better now 😁? |
|
Ran this branch on a live Sylius 2.2 shop with two channels. Each channel renders its own container id, and the channel-blind base bundle renders nothing. Pinned commit: SetupTwo Sylius channels, two hostnames, three GTM ids. The ids differ on purpose: one id on both channels cannot tell a per-channel resolution from the base bundle tagging everything.
google_tag_manager:
enabled: false
id: '%env(GTM_CONTAINER_ID)%' # GTM-BASEOFF
autoAppend: false
gtm:
channels:
WEB_EUR:
id: '%env(GTM_ID_WEB_EUR)%' # GTM-EUROWEB
enabled: true
FASHION_WEB:
id: '%env(GTM_ID_FASHION_WEB)%' # GTM-FASHION
enabled: trueResultThe rendered snippet, per host: Three assertions, all held:
Assertion 3 is the one that took a second pass. With the base bundle left Sylius picks the channel from the request |
Draft proposal for #151. Opening as a starting point for discussion — happy to redirect on shape, naming, or scope.
What it does
Adds optional
gtm.channels.<code>config. Per channel: containerid,enabledtoggle, and per-feature overrides (environment,route,context,events). Resolved atkernel.requestagainst Sylius'sChannelContextInterface.Existing setups behave identically — no config change required.
Design notes (full rationale in
scenarios/)ChannelGtmListener) rather than overloading existing listeners. xynnn's bundle exposessetId/enable/disable— fits naturally.ChannelFeatureResolverfor per-feature gating. Existing listeners get it as an optional last constructor arg (BC-safe — originalbool $enabledpreserved).gtm_channel_allows('events')) — the Sylius hook system'senabledflag is compile-time, so a runtime check was needed.scenarios/*.yamlwalks through 6 base + 3 EE scenarios (the EE-paired ones inform a parallel PR I'll open against the sister plugin).scenarios/scope-walkthrough.mdcovers the design decision.Tests & CI
mastertoo (pre-existingcomposer.jsonruntime.dotenv_pathincompatibility between SF6 and SF7). Out of scope here, but happy to take a stab in a separate PR if useful.Bundled fix
Removed two vestigial CI steps (cert install + webserver) — leftover from the Behat removal in cc0de1c. Drop or split out if you'd rather keep the PR single-purpose.
Open questions for you
gtm.channels.<code>ok, or prefer something else?scenarios/live in the repo, or move to a wiki/discussion?