This bundle integrates Google's Enhanced E-Commerce (GEEC) tracking into Sylius.
-
require the bundle with Composer:
$ composer require webburza/sylius-google-ecommerce-bundle
-
enable the bundle:
-
add application-specific bundle configuration
webburza_sylius_google_ecommerce: key: %webburza.sylius.google_ecommerce.key%
-
add application-specific bundle parameters (mainly, your Google Analytics key)
webburza.sylius.google_ecommerce.key: UA-12345678-1
-
enable GEEC block rendering in your Twig layout
<!-- App/ShopBundle/Resources/views/layout.html.twig --> <!-- add --> {{ google_ecommerce_render() }} <!-- /add --> </body> </html>
Having done this properly, you should have a functional Google Analytics tracking (without the e-commerce part). You can verify it works by using Google Analytics Debugger.
To enable the e-commerce part of the bundle, we need to tell it what the user is doing. We do this by using prepared Twig functions.
These are direct responses to user doing an action.
{{ google_ecommerce_impression(variant, {"list": list, "position": loop.index}) }}
mark a product impression in a listing.
Params:variant
, an instance of a SyliusProductVariant
list
, a (string) name of the list in which the product is being displayed, ie."search results"
position
, the position of the product in that list, starting from 1
{{ google_ecommerce_details(variant) }}
used only to indicate we're viewing a single product details view.
Params:variant
, an instance of a SyliusProductVariant
{{ google_ecommerce_checkout(order, {'step': 2}) }}
indicate the progression of a checkout.
Params:order
, an instance of a SyliusOrder
step
, which step are we currently on? Make sure to configure the checkout funnel, as described in the documentation.
{{ google_ecommerce_purchase(order) }}
indicate a successful transaction.
Params:order
, an instance of a SyliusOrder
These functions will render a handler which will react to user actions and invoke a direct action.
{{ google_ecommerce_click(variant, {"list": list}) }}
track the click on the product in a listing.
Params:variant
, an instance of a SyliusProductVariant
list
, a (string) name of the list in which the product is being displayed, ie."search results"
{{ google_ecommerce_cart(variant, {'action': 'add', 'callable': 'function(product) {product[\'variant\'] = \'TODO: which variant?\'; return product;}'}) }}
adding a product variant to cart.
Params:variant
, an instance of a SyliusProductVariant
event
, the Javascript event to react to, defaults to"submit"
action
, always"add"
callable
, an optional Javascript callback which adds additional product information (like variant)
{{ google_ecommerce_cart(variant, {'event': 'click', 'action': 'remove', 'variant': item.vars.value.variant.__toString()}) }}
removing a product from cart.
Params:variant
, an instance of a SyliusProductVariant
event
, as we're using a hyperlink, this must be"click"
action
, always"remove"
variant
, as we know what's the product variant at render time, we do not need the JS callback as for the adding.
{{ google_ecommerce_render() }}
render the current GEEC block. This was the function used in Basic installation.
Params: none.
This bundle is available under the MIT license.
TODO