CoreShop
CoreShop copied to clipboard
[Tracker] [TagManagerEnhancedEcommerce] Issues
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: https://github.com/coreshop/CoreShop/blob/bab33c0bdebd078b8a621ae3907fec1e8af098a9/src/CoreShop/Bundle/TrackingBundle/Tracker/Google/TagManager/TagManagerEnhancedEcommerce.php#L180 Others like trackCheckoutStep are working too.
@Cruiser13 I just tested it - it works on my side:
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
To-Do Summary:
Tracking Issues
trackCheckoutComplete
- [ ] Rename
total
torevenue
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 to1
. 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 intoecommerce
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 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.
The checkout_complete
is defined in thankYouAction
:
https://github.com/coreshop/CoreShop/blob/bab33c0bdebd078b8a621ae3907fec1e8af098a9/src/CoreShop/Bundle/FrontendBundle/Controller/CheckoutController.php#L329
I might be wrong, but every checkout process - regardless which payment provider is involved - should end there.
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.
@Cruiser13 I've added the total <> revenue to the to-do list: https://github.com/coreshop/CoreShop/issues/1613#issuecomment-829294847