Design or improve DataLayers as best

Hello people and interested people,

I myself have been familiarizing myself with Matomo for some time. After things didn’t work out so well with a few service providers, but I was able to learn something from them, I’m now in the process of doing it myself.

For me the biggest secret at the moment is the data layer. I would like to emphasize that I also load the Google Tag Manager via the Matomo Tag Manager.

So Matomo should get its data as well as Google Analytics 4 (that’s how the management wants it at the moment).

I’ve read through various sites and analyzed their data layers and also a few plugins that are open source.

That’s how I got to this DataLayer until now.

            <script>
                window.dataLayer = window.dataLayer || [
                    'wscBasicData': {
                        'usergroup':
                    {/literal}{if $sUserLoggedIn = "true"}{literal}
                            'K',
                    {/literal}{else}{literal}
                            'NK',
                    {/literal}{/if}{literal}
                        'locale': '{/literal}{$Locale}{literal}',
                        'pagetype': 'Pagetype', // Product, Category, checkoutSteps, Purchase, usw
                        'pagename': 'Pagename'
                    },
                    'wscSearchData': {
                        'searchTerm': 'EUR',
                        'searchList': 'Search Results', // Hard gecodet
                        'searchResults': 'SearchResults',
                        'searchProducts':
                            [
                                { // loop for the Products
                                    'name': 'Produktname',
                                    'sku': 'SKU',
                                    'price': 59.95,
                                    'brand': 'Brand',
                                    'position':1
                                }
                            ],
                    },
                    'wscEcommerce': {
                        'currency': 'EUR',
                        'category': 'Category',
                        'category':
                            [
                                { // loop for the Products
                                    'name': 'Produktname',
                                    'sku': 'SKU',
                                    'price': 59.95,
                                    'brand': 'Brand',
                                    'category': 'Categorie',
                                    'position':1
                                }
                            ],
                        'detail': {
                            'product':
                                [
                                    {
                                        'name': 'Produktname',
                                        'sku': 'SKU',
                                        'price': 59.95,
                                        'brand': 'Brand',
                                        'category': 'Categorie',
                                        'variant': 'Variantname'
                                    }
                                ]
                        }
                        'addCart': {
                            'products':
                                [
                                    {
                                        'name': 'Produktname',
                                        'sku': 'SKU',
                                        'quantity': 'Quantity',
                                        'price': 59.95,
                                        'variant': 'Variantname'
                                    }
                                ]
                        }
                        'removeCart': {
                            'products':
                                [
                                    {
                                        'name': 'Produktname',
                                        'sku': 'SKU',
                                        'quantity': 'Quantity',
                                        'price': 59.95,
                                        'variant': 'Variantname'
                                    }
                                ]
                        }
                        'cart': {
                            'step': 'checkoutStep',
                            'totalValue': 'TotalValue',
                            'products':
                                [
                                    { // loop for the Products
                                        'name': 'Produktname',
                                        'sku': 'SKU',
                                        'price': 59.95,
                                        'quantity': 'Quantity',
                                        'brand': 'Brand',
                                        'category': 'Categorie',
                                        'variant': 'Variantname'
                                    }
                                ]
                        }
                        'checkout': {
                            'step': 'checkoutStep',
                            'totalValue': 'TotalValue',
                            'optionShipping': 'ShippingOption',
                            'optionPayment': 'PaymentOption',
                            'products':
                                [
                                    { // loop for the Products
                                        'name': 'Produktname',
                                        'sku': 'SKU',
                                        'price': 59.95,
                                        'quantity': 'Quantity',
                                        'brand': 'Brand',
                                        'category': 'Categorie',
                                        'variant': 'Variantname'
                                    }
                                ]
                        }
                        'purchase': {
                            'orderID': 'checkoutStep',
                            'totalValue': 'TotalValue',
                            'optionShipping': 'ShippingOption',
                            'optionPayment': 'PaymentOption',
                            'optionShipping': 'ShippingOption',
                            'optionPayment': 'PaymentOption',
                            'tax': 'tax',
                            'shipping': 'ShippingCosts',
                            'products':
                                [
                                    { // loop for the Products
                                        'name': 'Produktname',
                                        'sku': 'SKU',
                                        'price': 59.95,
                                        'quantity': 'Quantity',
                                        'brand': 'Brand',
                                        'category': 'Categorie',
                                        'variant': 'Variantname'
                                    }
                                ]
                        }
                    }
                ];
            </script>

What do you think, did I forget something or what would you do differently?

As I said, I would like to feed the Matomo through this DataLayer as well as GA4.

I don’t have the login and register pages as well as shipping and payment yet. What data could you draw from this?

How do you do it with sliders or sales sliders like “Top products or Whoever bought X also bought Y”

Should this also be included in the DataLayer to recognize this?

Thank you for your time and I hope for a good exchange, because there is not much on the Internet about the topic after my research in the German-speaking area

I think your need is e-commerce.
Have a look at: