Google Analytics plugin for Sylius

Installs: 119 154

Dependents: 0

Suggesters: 0

Security: 0

Stars: 17

Watchers: 3

Forks: 11

Open Issues: 7


v3.0.0-alpha.5 2021-11-22 09:26 UTC


Latest Version Latest Unstable Version Software License Build Status

This plugin adds Google Analytics tracking to your store. It injects the tags directly and hence does not depend on third party tools like Google Tag Manager.


Step 1: Download the plugin

This plugin uses the TagBagBundle to inject scripts onto your page.

Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:

$ composer require setono/sylius-analytics-plugin

# Omit this line if you want to override layout.html.twig as described at
$ composer require setono/sylius-tag-bag-plugin

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the plugin

Then, enable the plugin by adding it to the list of registered plugins/bundles in config/bundles.php file of your project before (!) SyliusGridBundle:

$bundles = [
    Setono\TagBagBundle\SetonoTagBagBundle::class => ['all' => true],
    // Omit this line if you didn't install the SyliusTagBagPlugin in step 1
    Setono\SyliusTagBagPlugin\SetonoSyliusTagBagPlugin::class => ['all' => true],
    Setono\SyliusAnalyticsPlugin\SetonoSyliusAnalyticsPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],

Step 3: Configure plugin

# config/packages/_sylius.yaml
    # ...
    - { resource: "@SetonoSyliusAnalyticsPlugin/Resources/config/app/config.yaml" }
    # ...

Step 4: Import routing

# config/routes/setono_sylius_analytics.yaml
    resource: "@SetonoSyliusAnalyticsPlugin/Resources/config/routing.yaml"

Step 5: Update your database schema

$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate

Step 6: Create a property

When you create a property in Google Analytics you receive a tracking id which looks something like UA-12345678-1.

Now create a new property in your Sylius shop by navigating to /admin/properties/new. Remember to enable the property and enable the channels you want to track.

Step 7: You're ready!

The events that are tracked are located in the EventListener folder. To make your tracking even better you should create event listeners listening to the builder events fired in i.e. the PurchaseSubscriber.

Let's say you use the Brand plugin and want to enrich the items tracked with the brand of the product. That would look like this:



namespace App\EventListener;

use Loevgaard\SyliusBrandPlugin\Model\BrandAwareInterface;
use Setono\SyliusAnalyticsPlugin\Builder\ItemBuilder;
use Setono\SyliusAnalyticsPlugin\Event\BuilderEvent;
use Sylius\Component\Core\Model\OrderItemInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class AddBrandSubscriber implements EventSubscriberInterface
    public static function getSubscribedEvents(): array
        return [
            BuilderEvent::class => [

    public function addBrand(BuilderEvent $event): void
        $builder = $event->getBuilder();
        if(!$builder instanceof ItemBuilder) {
        $subject = $event->getSubject();
        if(!$subject instanceof OrderItemInterface) {
        $product = $subject->getProduct();
        if(!$product instanceof BrandAwareInterface) {


Ways you can contribute:

  • Translate messages and validators to your mother tongue
  • Create Behat tests that verifies the scripts are outputted on the respective pages
  • Create new event subscribers that handle Analytics events which are not implemented

Thank you!