Skip to content

Sylius integration with Google's Enhanced E-Commerce tracking within Google Analytics

License

Notifications You must be signed in to change notification settings

braune-digital/sylius-google-ecommerce-bundle

 
 

Repository files navigation

Sylius & Google Enhanced E-Commerce integration bundle

Build Status

This bundle integrates Google's Enhanced E-Commerce (GEEC) tracking into Sylius.

Documentation

Basic installation

  1. require the bundle with Composer:

    $ composer require webburza/sylius-google-ecommerce-bundle

  2. enable the bundle:

  3. add application-specific bundle configuration

    app/config/config.yml

    webburza_sylius_google_ecommerce: key: %webburza.sylius.google_ecommerce.key%

  4. add application-specific bundle parameters (mainly, your Google Analytics key)

    app/config/parameters.yml

    webburza.sylius.google_ecommerce.key: UA-12345678-1

  5. 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 Sylius ProductVariant
    • 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 Sylius ProductVariant
  • {{ google_ecommerce_checkout(order, {'step': 2}) }}
    indicate the progression of a checkout.
    Params:
    • order, an instance of a Sylius Order
    • 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 Sylius Order

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 Sylius ProductVariant
    • 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 Sylius ProductVariant
    • 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 Sylius ProductVariant
    • 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

About

Sylius integration with Google's Enhanced E-Commerce tracking within Google Analytics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 75.4%
  • HTML 24.6%