Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tracker] [TagManagerEnhancedEcommerce] Issues #1613

Open
Cruiser13 opened this issue Apr 19, 2021 · 6 comments
Open

[Tracker] [TagManagerEnhancedEcommerce] Issues #1613

Cruiser13 opened this issue Apr 19, 2021 · 6 comments
Labels

Comments

@Cruiser13
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

While the trackProduct() function works fine, the JS for the checkout_complete is not being added to the thank you page:


Others like trackCheckoutStep are working too.

@solverat solverat changed the title checkout_complete js of TagManagerEnhancedEcommerce not shown [Tracker] checkout_complete Code Part of TagManagerEnhancedEcommerce not shown Apr 29, 2021
@solverat
Copy link
Contributor

@Cruiser13 I just tested it - it works on my side:

image

But it does not send any event property.

Google also does not propose an event property in purchase section:

https://developers.google.com/tag-manager/enhanced-ecommerce#purchases

@solverat solverat changed the title [Tracker] checkout_complete Code Part of TagManagerEnhancedEcommerce not shown [Tracker] [TagManagerEnhancedEcommerce] Issues Apr 29, 2021
@solverat
Copy link
Contributor

solverat commented Apr 29, 2021

To-Do Summary:

Tracking Issues

trackCheckoutComplete

  • Rename total to revenue

trackProduct

  • remove quantity attribute

trackProductImpression

  • remove quantity attribute
  • submit impression as multi- instead of single-array

trackCartAdd

  • price attribute: I'm not sure about that but I think we need to use the cart item price instead of product price (which often can't be determinate (because of complex variant structure etc.)
  • quantity is hardcoded to 1. Use $quantity instead?

trackCartRemove

  • This event never gets tracked because after the tracker is called an instant redirectResponse gets executed. We need to add the tracker blocks to a flash bag for example and call it later in summaryAction.

My Workaround:

<?php

namespace AppBundle\Controller;

class CartController extends \CoreShop\Bundle\FrontendBundle\Controller\CartController
{
    public function summaryAction(Request $request)
    {
        // @todo: remove this method after #1613 has been fixed
        // @see: https://github.com/coreshop/CoreShop/issues/1613

        $flashBag = $this->container->get('session')->getFlashBag();
        $codeTracker = $this->get(CodeTracker::class);

        if ($flashBag instanceof FlashBag && $flashBag->has('_tracking')) {
            foreach ($flashBag->get('_tracking') as $bag) {
                if (is_array($bag)) {
                    foreach ($bag as $block) {
                        $codeTracker->addCodePart($block);
                    }
                }
            }
        }

        return parent::summaryAction($request);
    }

    public function removeItemAction(Request $request)
    {
        // @todo: remove this method after #1613 has been fixed
        // @see: https://github.com/coreshop/CoreShop/issues/1613

        $cartItem = $this->get('coreshop.repository.cart_item')->find($request->get('cartItem'));

        if ($cartItem instanceof CartItemInterface) {

            $this->get('coreshop.tracking.manager')->trackCartRemove(
                $this->getCart(),
                $cartItem->getProduct(),
                $cartItem->getQuantity()
            );

            $blocks = $this->get(CodeTracker::class)->getBlocks();

            if (is_array($blocks) && count($blocks) > 0) {
                $this->addFlash('_tracking', $blocks);
            }
        }

        return parent::removeItemAction($request);
    }
}

Template Issues

product_impression.js.twig

views/Tracking/gtm/enhanced/product_impression.js.twig

  • Add event (csProductImpressions) attribute
dataLayer.push({'event': 'csProductImpressions', 'ecommerce' : {{ actionData|json_encode()|raw }} });

product_view.js.twig

views/Tracking/gtm/enhanced/product_view.js.twig

  • Add event (csProductDetailImpressions) attribute
dataLayer.push({'event': 'csProductDetailImpressions', 'ecommerce': {'detail': {{ actionData|json_encode()|raw }} }});

checkout.js.twig

/views/Tracking/gtm/enhanced/checkout.js.twig

  • Move checkout attribute into ecommerce attribute (@see Docs)
dataLayer.push({'event': 'csCheckout', 'ecommerce': {'checkout': {{ actionData|json_encode()|raw }} }});

checkout_complete.js.twig

views/Tracking/gtm/enhanced/checkout_complete.js.twig

  • Add event (csPurchase) attribute
dataLayer.push({'event': 'csPurchase', 'ecommerce' : { 'purchase' : {{ actionData|json_encode()|raw }} } });

@solverat solverat added the bug label Apr 29, 2021
@Cruiser13
Copy link
Contributor Author

@solverat thank you for your reply! If it works for you I have to look deeper in our installation. Might be dependent on the payment method, some payment providers have weird redirections.

@solverat
Copy link
Contributor

The checkout_complete is defined in thankYouAction:

$this->get(TrackerInterface::class)->trackCheckoutComplete($order);

I might be wrong, but every checkout process - regardless which payment provider is involved - should end there.

@Cruiser13
Copy link
Contributor Author

I'll check that, thanks!
One thing I directly noted from your code - you do have "total" in the dataLayer while Google does expect "revenue" by default according to the docs. Might be an issue later - if I get the dataLayer filled at all.

@solverat
Copy link
Contributor

@Cruiser13 I've added the total <> revenue to the to-do list: #1613 (comment)

JustMe69 added a commit to JustMe69/CoreShop that referenced this issue Jun 24, 2022
fixing some of the listed issues in the ticket
Fixed:
- trackCheckoutComplete - Rename total to revenue
- trackProductImpression - remove quantity, brand, position, attribute
- trackCartAdd - quantity is hardcoded to 1. Use $quantity instead

Template issues
- product_impression.js.twig
- product_view.js.twig
- checkout.js.twig
- checkout_complete.js.twig

Not fixed:
- trackProductImpression - submit impression as multi- instead of single-array
- trackCartAdd - price attribute: I'm not sure about that but I think we need to use the cart item price instead of product price (which often can't be determinate (because of complex variant structure etc.)
- trackCartRemove
dpfaffenbauer added a commit that referenced this issue Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants