{"id":1873,"date":"2025-05-13T17:53:54","date_gmt":"2025-05-13T15:53:54","guid":{"rendered":"https:\/\/webmasterei-prange.de\/customer-data-in-the-datalayer-shopware-6-google-tag-manager-ga4-server-side-tracking\/"},"modified":"2025-09-23T22:02:39","modified_gmt":"2025-09-23T20:02:39","slug":"customer-data-in-the-datalayer-shopware-6-google-tag-manager-ga4-server-side-tracking","status":"publish","type":"post","link":"https:\/\/webmasterei-prange.de\/en\/customer-data-in-the-datalayer-shopware-6-google-tag-manager-ga4-server-side-tracking\/","title":{"rendered":"Customer data in the dataLayer Shopware 6 \u2013 Google Tag Manager (GA4 + Server Side Tracking)"},"content":{"rendered":"\n<p>This guide refers to the Shopware extension <strong>&#8221; <a href=\"https:\/\/store.shopware.com\/de\/wbm8772526137131m12\/google-tag-manager-ga4-server-side-tracking.html\" target=\"_blank\" rel=\"noreferrer noopener\">Google Tag Manager \/ GA4 \/ Server-Side Tracking<\/a> &#8220;<\/strong> by Bui Hinsche GmbH. The goal is to create a<code>login<\/code> event along with relevant customer data to the Google Tag Manager data layer. <\/p>\n\n<h2 class=\"wp-block-heading\" id=\"toc_Route_definieren\">Define login route<\/h2>\n\n<ul class=\"wp-block-list\">\n<li><strong>Administration \u2192 Settings \u2192 Google Tag Manager \u2192 Routes &amp; DataLayer<\/strong><\/li>\n\n\n\n<li>Create new route:<code>frontend.account.home.page<\/code> (Page after successful login)<\/li>\n<\/ul>\n\n<h2 class=\"wp-block-heading\" id=\"toc_DataLayerPayload_hinterlegen\">Deposit DataLayer payload<\/h2>\n\n<p>These variables should be configured in the Login module, as well as for all other page types \/ modules that are not the Finish Page.<\/p>\n\n<ul class=\"wp-block-list\">\n<li>Off-Canvas Cart<\/li>\n\n\n\n<li>Cart Page<\/li>\n\n\n\n<li>Confirm Page<\/li>\n\n\n\n<li>Add To Cart<\/li>\n\n\n\n<li>Remove From Cart<\/li>\n\n\n\n<li>Checkout Register Page<\/li>\n\n\n\n<li>Listing (ajax)<\/li>\n\n\n\n<li>Product Detail<\/li>\n\n\n\n<li>Home Page<\/li>\n\n\n\n<li>Login<\/li>\n<\/ul>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n\"event\": \"GA4_EVENTNAME\",\n\"user_data\": {\n  \"email\": {{ context.customer.email }}\n},\n\"user_roperties\": {\n  \"customer_group\": {{ context.currentCustomerGroup.name }},\n},\n\"user\": {\n  \"id\": {{ context.customer.id }},\n  \"number\": {{ context.customer.customerNumber }},\n  \"group\": {{ context.currentCustomerGroup.name }},\n  \"token\": {{ context.token }},\n  \"email\": {{ context.customer.email }}\n  }  \n}<\/pre>\n\n<p>Of course, these variables only work for logged-in customers. This data is not available for customers who are not logged in.   <\/p>\n\n<p>However, anyone looking for a session-wide identity in the data layer can create it using the shopping cart token. This token is accessible via the variable<code>{{ context.token }}<\/code> reachable. <\/p>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n\"user\": {\n  \"token\": \"{{ context.token }}\n  }\n}<\/pre>\n\n<h2 class=\"wp-block-heading\">DataLayer Payload for the Purchase Event<\/h2>\n\n<p>The data from the order can be used in the finish event. This also works reliably for guests. <\/p>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n\"event\": \"purchase\",\n  \"ecommerce\": {\n  \"transaction_id\": \"{{ page.order.orderNumber }}\",\n  \"value\": \"{{ page.order.price.netPrice }}\",\n  \"currency\": \"{{ context.currency.isoCode }}\"\n  },\n\"user_data\": {\n  \"email\": {{ page.order.orderCustomer.email }}\n},\n\"user_roperties\": {\n  \"customer_group\": {{ context.currentCustomerGroup.name }},\n},\n\"user\": {\n  \"id\": \"{{ context.customer.id }}\",\n  \"number\": \"{{ page.order.orderCustomer.customerNumber }}\",\n  \"group\": \"{{ context.currentCustomerGroup.name }}\",\n  \"token\": \"{{ context.token }}\"\n  \"email_sha256\": \"{{ page.order.orderCustomer.email }}\",\n  }\n}<\/pre>\n\n<p>What is worth highlighting in the code is the change of the<code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\"> ecommerce.value = {{page.order.positionPrice}}<\/code> recorded at the net value of the order.  <\/p>\n\n<p>If you want to use the <strong>net waiting value<\/strong> , you have to use a little more code:<\/p>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{# Net subtotal only item #}\n{%set itemsNetSubtotal = 0%}\n{% for item in page.order.lineItems %}\n  {% set itemTax = 0 %}\n  {% for t in item.price.calculatedTaxes %}\n  {% set itemTax = itemTax + t.tax %}\n  {% endfor %}\n  {% set itemNet = item.price.totalPrice - itemTax %}\n  {% set itemsNetSubtotal = itemsNetSubtotal + itemNet %}\n{% endfor %}\n\n{{ itemsNetSubtotal|number_format(2, '.', '') }}<\/pre>\n\n<p><\/p>\n\n<p>With these small changes, you can significantly improve the identification of users in the online shop with the help of server-side tracking.  <\/p>\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide refers to the Shopware extension &#8221; Google Tag Manager \/ GA4 \/ Server-Side Tracking &#8220; by Bui Hinsche GmbH. The goal is to create alogin event along with relevant customer data to the Google Tag Manager data layer. Define login route Deposit DataLayer payload These variables should be&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","slim_seo":{"title":"Login Event DataLayer Instructions for Shopware 6 with WBM GTM Extension","description":"How to set up a login event in Shopware 6 with the WBM GTM extension: DataLayer payload, route, trigger & debugging tips."},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-1873","post","type-post","status-publish","format-standard","hentry","category-website-tracking"],"taxonomy_info":{"category":[{"value":25,"label":"Website tracking"}]},"featured_image_src_large":false,"author_info":{"display_name":"Moritz Augustin","author_link":"https:\/\/webmasterei-prange.de\/en\/author\/moritz\/"},"comment_info":0,"category_info":[{"term_id":25,"name":"Website tracking","slug":"website-tracking","term_group":0,"term_taxonomy_id":25,"taxonomy":"category","description":"","parent":0,"count":11,"filter":"raw","cat_ID":25,"category_count":11,"category_description":"","cat_name":"Website tracking","category_nicename":"website-tracking","category_parent":0}],"tag_info":false,"_links":{"self":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts\/1873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/comments?post=1873"}],"version-history":[{"count":1,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts\/1873\/revisions"}],"predecessor-version":[{"id":1874,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts\/1873\/revisions\/1874"}],"wp:attachment":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/media?parent=1873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/categories?post=1873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/tags?post=1873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}