Magento 2: GTM checkout event from Mini Cart – window.checkoutGTMData is undefined on checkout page

I’m trying to fire a Google Tag Manager (GTM) checkout event when a customer clicks the “Checkout” button in the Mini Cart on my Magento 2 store.


Goal:
To push a GTM checkout event with product and customer data to window.dataLayer on the checkout page after the user clicks the mini cart’s checkout button.


  • Required Parameters to Push:

  • email (text)

  • product_id (int)

  • product_name (text)

  • produrl (text)

  • category (text)

  • price_mrp (int)

  • price_selling (int)

  • sku (text)

  • payment_method (text)

  • cart_total (int)

  • discount_code (text)

  • What I’ve Tried

Path: app/code/Vendor/GtmEvents/ViewModel/DataCollector.php

public function getQuoteProducts()
{
    $items = [];
    $quote = $this->checkoutSession->getQuote();
    foreach ($quote->getAllVisibleItems() as $item) {
        $product = $item->getProduct();
        $items[] = [
            'product_id' => (int)$product->getId(),
            'product_name' => $product->getName(),
            'produrl' => $product->getProductUrl(),
            'category' => implode(',', $product->getCategoryIds()),
            'price_mrp' => (int)$product->getPrice(),
            'price_selling' => (int)$item->getPrice(),
            'sku' => $product->getSku(),
        ];
    }
    return $items;
}