custom/plugins/DIScoGA4/src/Resources/views/storefront/ga4/meta-extra-information.html.twig line 1

Open in your IDE?
  1. {% block disco_meta_extra_information %}
  2. {% block disco_meta_extra_information_checkout_extra %}
  3.     {% if page.order.deliveries.first.shippingMethod is defined %}
  4.         <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  5.             window.ga4ShippingMethod = '{{ page.order.deliveries.first.shippingMethod.translated.name }}';
  6.         </script>
  7.     {% endif %}
  8.     {% if page.order.transactions.last.paymentMethod is defined %}
  9.         <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  10.             window.ga4PaymentMethod = '{{ page.order.transactions.last.paymentMethod.translated.name }}';
  11.         </script>
  12.     {% endif %}
  13.     {% if page.order.orderNumber is defined %}
  14.         <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  15.             window.ga4OrderNumber = '{{ page.order.orderNumber }}';
  16.         </script>
  17.     {% endif %}
  18. {% endblock %}
  19.     {% block disco_meta_extra_information_main %}
  20.         {% block disco_meta_extra_information_searchterm %}
  21.             {% if page.searchTerm %}
  22.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  23.                     window.searchTerm = '{{ page.searchTerm }}';
  24.                 </script>
  25.             {% endif %}
  26.         {% endblock %}
  27.         {% block disco_meta_extra_information_searchResult %}
  28.             {% if page.listing.total %}
  29.                 {% set searchResult = page.listing.total %}
  30.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  31.                     window.searchResult = '{{ page.listing.total }}';
  32.                 </script>
  33.             {% endif %}
  34.         {% endblock %}
  35.         {% block disco_meta_extra_information_config %}
  36.             <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  37.                 window.ga4RemarketingEnabled = false;
  38.                 window.googleAnalyticsEnabled = false;
  39.                 window.googleAdsEnabled = false;
  40.                 window.ga4AdvancedAdsEnabled = false;
  41.                 window.ga4Enabled = false;
  42.                 window.googleTagEnabled = false;
  43.                 {% if config('DIScoGA4.config.cookieConfig') %}
  44.                 window.ga4CookieConfig = '{{ config('DIScoGA4.config.cookieConfig') }}';
  45.                 {% else %}
  46.                 window.ga4CookieConfig = "standardCookies";
  47.                 {% endif %}
  48.                 {% if config('DIScoGA4.config.ga4cookieListener') %}
  49.                 window.ga4cookieListener = true;
  50.                 {% else %}
  51.                 window.ga4cookieListener = false;
  52.                 {% endif %}
  53.                  {% if config('DIScoGA4.config.generateLeadValue') %}
  54.                 window.generateLeadValue = '{{ config('DIScoGA4.config.generateLeadValue') }}';
  55.                         {% else %}
  56.                 window.generateLeadValue = 0.0;
  57.                 {% endif %}
  58.                 window.ga4Currency = '{{ context.currency.translated.shortName }}';
  59.             </script>
  60.             {% if config('DIScoGA4.config.googleTagEnabled') and config('DIScoGA4.config.googleTagId') %}
  61.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  62.                     window.ga4TagId = '{{ config('DIScoGA4.config.googleTagId')|raw }}';
  63.                     window.dataLayer = window.dataLayer || [];
  64.                     window.googleTagEnabled = true;
  65.                     window.ga4Enabled = true;
  66.                     window.ga4controllerName = '{{ controllerName|lower }}';
  67.                     window.ga4controllerAction = '{{ controllerAction|lower }}';
  68.                     window.ga4activeNavigationId = '{{ page.header.navigation.active.id }}';
  69.                     window.ga4activeNavigationName = '{{ page.header.navigation.active.name }}';
  70.                     window.ga4affiliation = '{{ context.salesChannel.name }}';
  71.                     window.ga4salesChannelName = '{{ context.salesChannel.name }}';
  72.                     window.ga4salesChannelId = '{{ context.salesChannel.id }}';
  73.                     {% if config('DIScoGA4.config.enableUserId') %}
  74.                     window.ga4enableUserId = true;
  75.                     {% else %}
  76.                     window.ga4enableUserId = false;
  77.                     {% endif %}
  78.                     {% if config('DIScoGA4.config.uvpPriceAsCoupon') %}
  79.                     window.ga4upCoupon = true;
  80.                     {% else %}
  81.                     window.ga4upCoupon = false;
  82.                     {% endif %}
  83.                     {% if config('DIScoGA4.config.graduatedPriceAsCoupon') %}
  84.                     window.ga4gpCoupon = true;
  85.                     {% else %}
  86.                     window.ga4gpCoupon = false;
  87.                     {% endif %}
  88.                 </script>
  89.             {% endif %}
  90.             {% if config('DIScoGA4.config.googleAnalyticsEnabled') %}
  91.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  92.                     window.googleAnalyticsEnabled = true;
  93.                 </script>
  94.             {% endif %}
  95.         {% endblock %}
  96.         {% block disco_meta_extra_information_usertracking %}
  97.             {% if context.customer is not null and not context.customer.guest ? 1 : 0 %}
  98.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  99.                     window.ga4UserLoggedIn = true;
  100.                 </script>
  101.                 {% if config('DIScoGA4.config.enableUserId') %}
  102.                     <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  103.                         window.ga4UserId = '{{ context.customer.id }}';
  104.                     </script>
  105.                 {% endif %}
  106.             {% else %}
  107.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  108.                     window.ga4UserLoggedIn = false;
  109.                     if(localStorage.getItem("loginSent")) localStorage.removeItem("loginSent")
  110.                 </script>
  111.             {% endif %}
  112.             {% if config('DIScoGA4.config.googleAdsEnabled') %}
  113.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  114.                     {% if config('DIScoGA4.config.enableRemarketing') %}
  115.                     window.ga4RemarketingEnabled = true;
  116.                     {% else %}
  117.                     window.ga4RemarketingEnabled = false;
  118.                     {% endif %}
  119.                     window.googleAdsEnabled = true;
  120.                     {% if config('DIScoGA4.config.enableAdsAdvanced') %}
  121.                     window.ga4AdvancedAdsEnabled = true;
  122.                     {% else %}
  123.                     window.ga4AdvancedAdsEnabled = false;
  124.                     {% endif %}
  125.                     {% if config('DIScoGA4.config.adsValueNetto') and config('DIScoGA4.config.adsValueNetto') == "netto" %}
  126.                     window.adsValueNetto = true;
  127.                     {% else %}
  128.                     window.adsValueNetto= false;
  129.                     {% endif %}
  130.                     {% if config('DIScoGA4.config.transationIdMethod') and config('DIScoGA4.config.transationIdMethod') == "trueOrderId" %}
  131.                     window.transationIdMethod = "trueOrderId";
  132.                     {% else %}
  133.                     window.transationIdMethod= "hashedOrderId";
  134.                     {% endif %}
  135.                 </script>
  136.                 {% if context.customer is not null %}
  137.                     <span class='d-none ga4-hidden-ads-information'
  138.                           data-feedcountry='{{ config('DIScoGA4.config.feedCountry') }}'
  139.                           data-feedlangage='{{ config('DIScoGA4.config.feedLanguage') }}' {% if config('DIScoGA4.config.enableAdsAdvanced') %} data-useremail='{{ context.customer.email }}' data-phone='{{ context.customer.activeBillingAddress.phoneNumber }}' data-firstname='{{ context.customer.activeBillingAddress.firstName }}' data-lastname='{{ context.customer.activeBillingAddress.lastName }}' data-street='{{ context.customer.activeBillingAddress.street }}' data-city='{{ context.customer.activeBillingAddress.city }}' data-region='{{ context.customer.activeBillingAddress.countryState.name }}' data-zip='{{ context.customer.activeBillingAddress.zipcode }}' data-land='{{ context.customer.activeBillingAddress.country.name }}' {% endif %}></span>
  140.                 {% endif %}
  141.             {% endif %}
  142.         {% endblock %}
  143.         {% block disco_meta_extra_information_specialcase %}
  144.             <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  145.                 if (window.googleAdsEnabled !== true && window.googleAnalyticsEnabled !== true) {
  146.                     window.ga4Enabled = false;
  147.                 }
  148.             </script>
  149.         {% endblock %}
  150.     {% endblock %}
  151.     {% block disco_meta_extra_information_extensions %}
  152.         
  153.         {% set productsExtension = context.context.extensions.disGA4ProductsExtension %}
  154.         {% set lineItemsExtension = context.context.extensions.disGA4LineItemsExtension %}
  155.         {% if productsExtension is not null %}
  156.             <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  157.                 window.ga4Product = {};
  158.             </script>
  159.             {% for product in productsExtension %}
  160.                 {% set price = product.calculatedPrice %}
  161.                 {% if product.calculatedPrices|length == 1 %}
  162.                     {% set price = product.calculatedPrices.first %}
  163.                 {% endif %}
  164.                 {% set listPrice = price.listPrice %}
  165.                 {% if listPrice.percentage > 0 %}
  166.                     {% set listingPrice = price.listPrice.price %}
  167.                 {% else %}
  168.                     {% set listingPrice = price.unitPrice %}
  169.                 {% endif %}
  170.                 {% set variantText = '' %}
  171.                 {% if product.variation %}
  172.                     {% for variation in product.variation %}
  173.                         {% set variantText = variantText ~ ' ' ~ variation.group ~ ' ' ~ variation.option ~ ' -' %}
  174.                     {% endfor %}
  175.                 {% endif %}
  176.                 {% set seoCategorie = product.seoCategory %}
  177.                 {% set standardCategories = product.categories %}
  178.                 {% set ga4Id = 'ga4-product-' ~ product.id %}
  179.                 {% if product.manufacturer  %}
  180.                     {% set itemBrand = product.manufacturer.translated.name  %}
  181.                 {% else %}
  182.                     {% set itemBrand = ga4GetManufacturer(product.manufacturerId,context.context)  %}
  183.                 {% endif %}
  184.                 {% if product.calculatedPrices.count > 0 %}
  185.                     {% set startPrice = product.calculatedPrices.first.unitPrice %}
  186.                     {% set hasGraduatedPrice = true %}
  187.                  {% else %}
  188.                      {% set startPrice = price.unitPrice %}
  189.                      {% set hasGraduatedPrice = false %}
  190.                 {% endif %}
  191.                 <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  192.                     window.ga4Product['{{ product.id }}'] = {};
  193.                     window.ga4Product['{{ product.id }}']['item_brand'] = '{{ itemBrand }}';
  194.                     window.ga4Product['{{ product.id }}']['item_name'] = '{{ product.translated.name }}';
  195.                     window.ga4Product['{{ product.id }}']['minPurchase'] = '{{ product.minPurchase }}';
  196.                     window.ga4Product['{{ product.id }}']['shopware_id'] = '{{ product.id }}';
  197.                     window.ga4Product['{{ product.id }}']['item_id'] = '{{ product.productNumber }}';
  198.                     window.ga4Product['{{ product.id }}']['realPrice'] = '{{ listingPrice }}';
  199.                     window.ga4Product['{{ product.id }}']['item_startPrice'] = '{{ startPrice }}';
  200.                     window.ga4Product['{{ product.id }}']['item_hasGraduatedPrice'] = '{{ hasGraduatedPrice }}';
  201.                     {% if controllerName|lower == 'product' %}
  202.                         window.ga4Product['{{ product.id }}']['item_list_id'] = 'product';
  203.                         window.ga4Product['{{ product.id }}']['item_list_name'] = 'product';
  204.                     {% elseif controllerName|lower == 'navigation' %}
  205.                         window.ga4Product['{{ product.id }}']['item_list_id'] = '{{ page.header.navigation.active.id }}';
  206.                         window.ga4Product['{{ product.id }}']['item_list_name'] = '{{ page.header.navigation.active.name }}';
  207.                     {% elseif controllerName|lower == 'search' %}
  208.                         window.ga4Product['{{ product.id }}']['item_list_id'] = 'search';
  209.                         window.ga4Product['{{ product.id }}']['item_list_name'] = 'search';
  210.                     {% endif %}
  211.                         window.ga4Product['{{ product.id }}']['taxRate'] = '{{ product.tax.taxRate }}';
  212.                         window.ga4Product['{{ product.id }}']['cheapest'] = '{{ price.unitPrice }}';
  213.                         window.ga4Product['{{ product.id }}']['currency'] = '{{ context.currency.translated.shortName }}';
  214.                         window.ga4Product['{{ product.id }}']['item_variant'] = '{{ variantText | trim(' ','left') | trim('-','right') }}';
  215.                     {% if seoCategorie %}
  216.                     {% set breadcrumbCategories = sw_breadcrumb_full(seoCategorie, context.context) %}
  217.                     {% set counter = 1 %}
  218.                     {% for breadcrumbCategory in breadcrumbCategories %}
  219.                         {% set name = breadcrumbCategory.translated.name %}
  220.                             {% if counter == 1  %}
  221.                         window.ga4Product['{{ product.id }}']['item_category'] = '{{ name }}';
  222.                            {% else  %}
  223.                     window.ga4Product['{{ product.id }}']['item_category{{ counter }}'] = '{{ name }}';
  224.                     {% endif %}
  225.                         {% set counter = counter + 1 %}
  226.                     {% endfor %}
  227.                     {% elseif standardCategories %}
  228.                     {% set counter = 1 %}
  229.                     {% for standardCategory in standardCategories %}
  230.                     {% set breadcrumbCategories = sw_breadcrumb_full(standardCategory, context.context) %}
  231.                     {% for breadcrumbCategory in breadcrumbCategories %}
  232.                     {% set name = breadcrumbCategory.translated.name %}
  233.                     {% if counter == 1  %}
  234.                     window.ga4Product['{{ product.id }}']['item_category'] = '{{ name }}';
  235.                     {% else  %}
  236.                     window.ga4Product['{{ product.id }}']['item_category{{ counter }}'] = '{{ name }}';
  237.                     {% endif %}
  238.                     {% set counter = counter + 1 %}
  239.                     {% endfor %}
  240.                     {% endfor %}
  241.                     {% elseif product.categoryTree %}
  242.                     {% set categories = ga4GetCategories(product.categoryTree,context.context) %}
  243.                     {% if categories %}
  244.                     {% set counter = 0 %}
  245.                     {% for category in categories %}
  246.                     {% if counter > 0 %}
  247.                     {% if counter == 1  %}
  248.                     window.ga4Product['{{ product.id }}']['item_category'] = '{{ category.name  }}';
  249.                     {% else  %}
  250.                     window.ga4Product['{{ product.id }}']['item_category{{ counter }}'] = '{{ category.name  }}';
  251.                     {% endif %}
  252.                     {% endif %}
  253.                     {% set counter = counter + 1 %}
  254.                     {% endfor %}
  255.                     {% endif %}
  256.                     {% endif %}
  257.                 </script>
  258.             {% endfor %}
  259.         {% endif %}
  260.         {% if lineItemsExtension is null %}
  261.         {% if page.cart  %}
  262.             {% set lineItemsExtension = page.cart.lineItems %}
  263.         {% endif %}
  264.         {% if page.order  %}
  265.             {% set lineItemsExtension = page.order.lineItems %}
  266.         {% endif %}
  267.         {% endif %}
  268.         {% if lineItemsExtension is not null %}
  269.             <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  270.                 window.ga4LineItem = {};
  271.             </script>
  272.             {% for lineItem in lineItemsExtension %}
  273.                 {% set fullProduct = ga4GetProduct(lineItem.id,context.context) %}
  274.                 {% if fullProduct %}
  275.                     {% set variantText = '' %}
  276.                     {% if lineItem.payload.options %}
  277.                         {% for variation in lineItem.payload.options %}
  278.                             {% set variantText = variantText ~ ' ' ~ variation.group ~ ' ' ~ variation.option ~ '-' %}
  279.                         {% endfor %}
  280.                     {% endif %}
  281.                     {% set categories = ga4GetCategories(fullProduct.categoryTree,context.context) %}
  282.                     {% set breadcrumbText = '' %}
  283.                     {% set ga4Id = 'ga4-lineitem-' ~ fullProduct.id %}
  284.                     <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  285.                     window.ga4LineItem['{{ fullProduct.id }}'] = {};
  286.                     {% if categories %}
  287.                     {% set counter = 1 %}
  288.                     {% for category in categories %}
  289.                     {% set name = category.name %}
  290.                     {% if counter == 1  %}
  291.                     window.ga4LineItem['{{ fullProduct.id }}']['item_category'] = '{{ name }}';
  292.                     {% else  %}
  293.                     window.ga4LineItem['{{ fullProduct.id }}']['item_category{{ counter }}'] = '{{ name }}';
  294.                     {% endif %}
  295.                     {% set counter = counter + 1 %}
  296.                     {% endfor %}
  297.                     {% endif %}
  298.                     {% if fullProduct.manufacturer  %}
  299.                     {% set itemBrand = fullProduct.manufacturer.translated.name  %}
  300.                     {% else %}
  301.                     {% set itemBrand = ga4GetManufacturer(fullProduct.manufacturerId,context.context)  %}
  302.                     {% endif %}
  303.                     {% if lineItem.price.taxRules.length > 0  %}
  304.                     {% set taxes = lineItem.price.taxRules[0].taxRate  %}
  305.                     {% else %}
  306.                     {% set taxes = 0  %}
  307.                     {% endif %}
  308.                     window.ga4LineItem['{{ fullProduct.id }}']['shopware_id'] = '{{ fullProduct.id }}';
  309.                     window.ga4LineItem['{{ fullProduct.id }}']['item_id'] = '{{ fullProduct.productNumber }}';
  310.                     window.ga4LineItem['{{ fullProduct.id }}']['item_brand'] = '{{ itemBrand }}' ;
  311.                     window.ga4LineItem['{{ fullProduct.id }}']['item_name'] = '{{ lineItem.label }}';
  312.                     window.ga4LineItem['{{ fullProduct.id }}']['item_type'] = '{{ lineItem.type }}' ;
  313.                     window.ga4LineItem['{{ fullProduct.id }}']['quantity'] = '{{ lineItem.quantity }}';
  314.                     window.ga4LineItem['{{ fullProduct.id }}']['realprice'] = '{{ fullProduct.calculatedPrice.unitPrice }}';
  315.                     window.ga4LineItem['{{ fullProduct.id }}']['taxes'] = '{{  taxes }}';
  316.                     window.ga4LineItem['{{ fullProduct.id }}']['cheapest'] = '{{ fullProduct.calculatedCheapestPrice.unitPrice }}';
  317.                     window.ga4LineItem['{{ fullProduct.id }}']['item_variant'] = '{{ variantText | trim(' ','left') | trim('-','right') }}';
  318.                     window.ga4LineItem['{{ fullProduct.id }}']['categories'] = '{{ breadcrumbText | trim('>') }}';
  319.                     window.ga4LineItem['{{ fullProduct.id }}']['price'] = '{{ checkoutPrice }}';
  320.                     window.ga4LineItem['{{ fullProduct.id }}']['currency'] = '{{ context.currency.translated.shortName }}';
  321.                     </script>
  322.                 {% else %}
  323.                     <script {% if app.session.get('csp_nonce')  %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
  324.                         window.ga4LineItem['{{ lineItem.id }}'] = [];
  325.                         window.ga4LineItem['{{ lineItem.id }}']['shopware_id'] = '{{ lineItem.id }}';
  326.                         window.ga4LineItem['{{ lineItem.id }}']['item_id'] = '{{ lineItem.payload.productNumber }}';
  327.                         window.ga4LineItem['{{ lineItem.id }}']['item_name'] = '{{ lineItem.label }}';
  328.                         window.ga4LineItem['{{ lineItem.id }}']['type'] = '{{ lineItem.type }}' ;
  329.                         window.ga4LineItem['{{ lineItem.id }}']['quantity'] = '{{ lineItem.quantity }}';
  330.                         window.ga4LineItem['{{ lineItem.id }}']['price'] = '{{ lineItem.price.totalPrice }}';
  331.                         window.ga4LineItem['{{ lineItem.id }}']['taxes'] = '{{  lineItem.price.taxRules[0].taxRate }}';
  332.                     </script>
  333.                 {% endif %}
  334.             {% endfor %}
  335.         {% endif %}
  336.     {% endblock %}
  337.     {% block disco_hidden_line_items_information %}
  338.         {% if page.cart  %}
  339.             {% set discocart= page.cart %}
  340.             {% set discolineItems = page.cart.lineItems %}
  341.             <div class="d-none discoga4-header-hidden-line-items-information"
  342.             data-currency="{{ context.currency.translated.shortName }}"
  343.             data-shipping="{{ discocart.deliveries.shippingCosts.sum().totalPrice }}"
  344.             data-value="{{ discocart.price.totalPrice }}"
  345.             data-tax="{{ discocart.price.calculatedTaxes.amount }}"
  346.             >
  347.         {% endif  %}
  348.         {% if page.order  %}
  349.             {% set discocart= page.order %}
  350.             {% set discolineItems = page.order.lineItems %}
  351.                 <div class="d-none discoga4-header-hidden-line-items-information"
  352.                      data-currency="{{ context.currency.translated.shortName }}"
  353.                      data-shipping="{{ discocart.shippingTotal }}"
  354.                      data-value="{{ discocart.price.totalPrice }}"
  355.                      data-tax="{{ discocart.price.calculatedTaxes.amount }}"
  356.                 >
  357.         {% endif  %}
  358.         {% if discocart  %}
  359.             {% for lineItem in discolineItems  %}
  360.                 {% if lineItem.priceDefinition.price %}
  361.                     {% set gaPrice = lineItem.priceDefinition.price %}
  362.                 {% else %}
  363.                     {% set gaPrice = lineItem.price.totalPrice %}
  364.                 {% endif %}
  365.                 {% block disco_hidden_line_item_information %}
  366.                     <span class="hidden-line-item"
  367.                           data-id="{{ lineItem.id }}"
  368.                           data-name="{{ lineItem.label }}"
  369.                           data-type="{{ lineItem.type }}"
  370.                           data-sku="{{ lineItem.payload.productNumber }}"
  371.                           data-quantity="{{ lineItem.quantity }}"
  372.                           data-price="{{ gaPrice }}">
  373.                 </span>
  374.                 {% endblock %}
  375.             {% endfor %}
  376.         </div>
  377.         {% endif %}
  378.     {% endblock %}
  379. {% endblock %}