webburza / sylius-google-ecommerce-bundle
Sylius integration with Google's Enhanced E-Commerce tracking within Google Analytics
Installs: 727
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 2
Forks: 8
Open Issues: 1
Type:symfony-bundle
Requires
- sylius/core: ^v1.0.0-beta.1
- twig/twig: ^1.27
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- phing/phing: ^2.16
- phpmd/phpmd: ^2.5
- phpunit/phpunit: ^5.7
- sebastian/phpcpd: ^2.0
This package is not auto-updated.
Last update: 2025-01-05 02:25:55 UTC
README
This bundle integrates Google's Enhanced E-Commerce (GEEC) tracking into Sylius.
Documentation
Basic installation
-
require the bundle with Composer:
$ composer require webburza/sylius-google-ecommerce-bundle
-
enable the bundle:
-
add application-specific bundle configuration
app/config/config.yml
webburza_sylius_google_ecommerce: key: %webburza.sylius.google_ecommerce.key%
-
add application-specific bundle parameters (mainly, your Google Analytics key)
app/config/parameters.yml
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.
Enabling the e-commerce integration
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.
Direct action 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
Action handler functions
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.
License
This bundle is available under the MIT license.
Contributing
TODO