spinbits/sylius-google-analytics-plugin

Ready for multiple channels

Closed this issue · 4 comments

So far the plugin uses only one ID.

spinbits_sylius_google_analytics4:
    id: "G-XXXXXXXXXX"

To separate channels / domain, it need to have id for channel - regarding enable ID to channel / domain.

Thanks for opening the issue. We have plans to add it after New Year.

I did it directly with the channel - I think when you setup a channel, it has to stuck there.

`
use Twig\Environment;
use Sylius\Component\Channel\Context\ChannelContextInterface;

class RenderHeadTwigFactory
{
/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
    ChannelContextInterface $channelContext,
    private Environment $twig,
    private string $additionalParams,
    private string $templateName,
    private bool $enabled
) {
    $this->channelContext = $channelContext;
    $this->additionalParams = $additionalParams ? '&'.trim($additionalParams,'&') : '';
}

public function render(): string
{
    return !$this->enabled ? '' : $this->twig->render(
        $this->templateName, [
            'id' => $this->channelContext->getChannel()->getGoogle(),
            'url_suffix' => $this->additionalParams
        ]
    );
}

}
`

`services:
_defaults:
autowire: true
autoconfigure: true
public: false

Spinbits\SyliusGoogleAnalytics4Plugin\:
    resource: '../../'
    exclude:
        - '../../DependencyInjection/'
        - '../../Entity/'
        - '../../Kernel.php'

Spinbits\SyliusGoogleAnalytics4Plugin\Factory\RenderHeadTwigFactory:
    arguments:
        $channelContext: '@sylius.context.channel'
        $enabled: '%spinbits_sylius_google_analytics4.enabled%'
        $additionalParams: '%spinbits_sylius_google_analytics4.additionalParameters%'
        $templateName: '%spinbits_sylius_google_analytics4.templateName%'

Spinbits\SyliusGoogleAnalytics4Plugin\EventListener\RenderViewListener:
    tags:
        - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }

Spinbits\SyliusGoogleAnalytics4Plugin\Factory\ItemFactory:
    arguments:
        $productVariantResolver: '@sylius.product_variant_resolver.default'

Spinbits\SyliusGoogleAnalytics4Plugin\Factory\EventsBagSessionFactory:
    decorates: session.factory
    arguments: ['@.inner']`

and the sylius channel admin with forms etc...

You are almost there. You are very welcome to open a PR with introduction for above changes :)

It is already implemented in v1.1.0