Developed with love by KnpLabs Hire us for your project!
35

sylius-google-ecommerce-bundle

by webburza

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

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:

    <?php
    // app/AppKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new \Webburza\Sylius\GoogleEcommerceBundle\WebburzaSyliusGoogleEcommerceBundle(),
            // ...
        );
    }
    
  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

The MIT License (MIT)

Copyright (c) 2016 web.burza

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
webburza_sylius_google_ecommerce:
key: ~ # Required
  • fix(bundle) proper Symfony configuration
    By dkarlovi, 2 years ago
  • feature(lib) add refund support (#8)
    By web-flow, 2 years ago
  • fix(lib) update to be compatible with Sylius 1.0
    By dkarlovi, 2 years ago
  • Merge pull request #4 from Devolicious/master
    By web-flow, 2 years ago
  • allow sylius dev-master
    By web-flow, 2 years ago
  • Merge pull request #3 from webburza/feature/upgrade
    By web-flow, 2 years ago
  • feature(upgrade): Drop support for PHP 5.5
    By ychanan, 2 years ago
  • feature(upgrade): Bump to Sylius 0.19
    By ychanan, 2 years ago
  • feature(upgrade): Bump for Sylius 0.18
    By ychanan, 2 years ago
  • tests(bundle) enable GitLab CI builds
    By dkarlovi, 3 years ago
  • doc(bundle) add travis CI build status to README.md
    By dkarlovi, 3 years ago
  • Merge pull request #1 from webburza/feature/tests
    By dkarlovi, 3 years ago
  • tests(client) add cart add/remove handler tests
    By dkarlovi, 3 years ago
  • style(tests) php-cs-fixer
    By dkarlovi, 3 years ago
  • tests(client) add click handler test
    By dkarlovi, 3 years ago
  • fix(bundle) reduce PHPUnit version to ^4.8
    By dkarlovi, 3 years ago
  • fix(bundle) depend on sylius/core, not on sylius/sylius
    By dkarlovi, 3 years ago
  • tests(bundle) fix PHPUnit path for Travis CI build
    By dkarlovi, 3 years ago
  • tests(bundle) disable Xdebug on Travis CI (composer runs into trouble)
    By dkarlovi, 3 years ago
  • doc(bundle) placeholder for Travis CI build icon
    By dkarlovi, 3 years ago
  • tests(bundle) enable Travis CI build (for GitHub)
    By dkarlovi, 3 years ago
  • tests(client) rename fixtures to better reflect their purpose
    By dkarlovi, 3 years ago
  • tests(client) add purchase action test
    By dkarlovi, 3 years ago
  • tests(client) add checkout action test
    By dkarlovi, 3 years ago
  • tests(client) add proper code coverage declarations
    By dkarlovi, 3 years ago
  • tests(bundle) enable strict mode for PHPUnit runner & code coverage
    By dkarlovi, 3 years ago
  • refactor(client) make Client::addProduct() private
    By dkarlovi, 3 years ago
  • tests(bundle) add test for detail impression
    By dkarlovi, 3 years ago
  • refactor(bundle) rename addImpressionAction() to addImpression()
    By dkarlovi, 3 years ago
  • tests(bundle) add product impression test
    By dkarlovi, 3 years ago