At our web agency, we use the Google Tag Manager plugin by codiverse for a Shopware 5 customer. The plugin prepares a dataLayer that can then be conveniently read via Google Tag Manager. However, we were missing the current shopping cart value, which in the basic configuration of the online shop / plugin was only provided during checkout.
codiverse provides a good guide for this purpose. At https://www.codiverse.de/shopware-gtm-plugin-verfuegbare-events-werte-im-datalayer/ you can find information about the available filter events. The agency explains in detail how to hook into these events at https://www.codiverse.de/tutorial-gtm-plugin-ueber-events-erweitern-shopware-5/ and even offers the basic structure of the extension plugin as a download.
In our case, we did not need the customer data and therefore did not hook into
Dtgs_GoogleTagManager_Components_TagManagerHelper_GetCustomerTags_FilterCustomerTags
but instead into
Dtgs_GoogleTagManager_Components_TagManagerHelper_GetGeneralTags_FilterGeneralTags
In our function
public function myFilterGeneralTags(Enlight_Event_EventArgs $args)
all we then had to do was retrieve the shopping cart value and pass it to the tags variable using (identifier shown as an example)
$tags['ecoBasketAmount'] = Shopware()->Session()->sBasketAmount;
That's all there is to it. Seen at our agency in an online shop with Shopware 5.
