{% block disco_meta_extra_information %}
{% block disco_meta_extra_information_checkout_extra %}
{% if page.order.deliveries.first.shippingMethod is defined %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4ShippingMethod = '{{ page.order.deliveries.first.shippingMethod.translated.name }}';
</script>
{% endif %}
{% if page.order.transactions.last.paymentMethod is defined %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4PaymentMethod = '{{ page.order.transactions.last.paymentMethod.translated.name }}';
</script>
{% endif %}
{% if page.order.orderNumber is defined %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4OrderNumber = '{{ page.order.orderNumber }}';
</script>
{% endif %}
{% endblock %}
{% block disco_meta_extra_information_main %}
{% block disco_meta_extra_information_searchterm %}
{% if page.searchTerm %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.searchTerm = '{{ page.searchTerm }}';
</script>
{% endif %}
{% endblock %}
{% block disco_meta_extra_information_searchResult %}
{% if page.listing.total %}
{% set searchResult = page.listing.total %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.searchResult = '{{ page.listing.total }}';
</script>
{% endif %}
{% endblock %}
{% block disco_meta_extra_information_config %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4RemarketingEnabled = false;
window.googleAnalyticsEnabled = false;
window.googleAdsEnabled = false;
window.ga4AdvancedAdsEnabled = false;
window.ga4Enabled = false;
window.googleTagEnabled = false;
{% if config('DIScoGA4.config.cookieConfig') %}
window.ga4CookieConfig = '{{ config('DIScoGA4.config.cookieConfig') }}';
{% else %}
window.ga4CookieConfig = "standardCookies";
{% endif %}
{% if config('DIScoGA4.config.ga4cookieListener') %}
window.ga4cookieListener = true;
{% else %}
window.ga4cookieListener = false;
{% endif %}
{% if config('DIScoGA4.config.generateLeadValue') %}
window.generateLeadValue = '{{ config('DIScoGA4.config.generateLeadValue') }}';
{% else %}
window.generateLeadValue = 0.0;
{% endif %}
window.ga4Currency = '{{ context.currency.translated.shortName }}';
</script>
{% if config('DIScoGA4.config.googleTagEnabled') and config('DIScoGA4.config.googleTagId') %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4TagId = '{{ config('DIScoGA4.config.googleTagId')|raw }}';
window.dataLayer = window.dataLayer || [];
window.googleTagEnabled = true;
window.ga4Enabled = true;
window.ga4controllerName = '{{ controllerName|lower }}';
window.ga4controllerAction = '{{ controllerAction|lower }}';
window.ga4activeNavigationId = '{{ page.header.navigation.active.id }}';
window.ga4activeNavigationName = '{{ page.header.navigation.active.name }}';
window.ga4affiliation = '{{ context.salesChannel.name }}';
window.ga4salesChannelName = '{{ context.salesChannel.name }}';
window.ga4salesChannelId = '{{ context.salesChannel.id }}';
{% if config('DIScoGA4.config.enableUserId') %}
window.ga4enableUserId = true;
{% else %}
window.ga4enableUserId = false;
{% endif %}
{% if config('DIScoGA4.config.uvpPriceAsCoupon') %}
window.ga4upCoupon = true;
{% else %}
window.ga4upCoupon = false;
{% endif %}
{% if config('DIScoGA4.config.graduatedPriceAsCoupon') %}
window.ga4gpCoupon = true;
{% else %}
window.ga4gpCoupon = false;
{% endif %}
</script>
{% endif %}
{% if config('DIScoGA4.config.googleAnalyticsEnabled') %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.googleAnalyticsEnabled = true;
</script>
{% endif %}
{% endblock %}
{% block disco_meta_extra_information_usertracking %}
{% if context.customer is not null and not context.customer.guest ? 1 : 0 %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4UserLoggedIn = true;
</script>
{% if config('DIScoGA4.config.enableUserId') %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4UserId = '{{ context.customer.id }}';
</script>
{% endif %}
{% else %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4UserLoggedIn = false;
if(localStorage.getItem("loginSent")) localStorage.removeItem("loginSent")
</script>
{% endif %}
{% if config('DIScoGA4.config.googleAdsEnabled') %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
{% if config('DIScoGA4.config.enableRemarketing') %}
window.ga4RemarketingEnabled = true;
{% else %}
window.ga4RemarketingEnabled = false;
{% endif %}
window.googleAdsEnabled = true;
{% if config('DIScoGA4.config.enableAdsAdvanced') %}
window.ga4AdvancedAdsEnabled = true;
{% else %}
window.ga4AdvancedAdsEnabled = false;
{% endif %}
{% if config('DIScoGA4.config.adsValueNetto') and config('DIScoGA4.config.adsValueNetto') == "netto" %}
window.adsValueNetto = true;
{% else %}
window.adsValueNetto= false;
{% endif %}
{% if config('DIScoGA4.config.transationIdMethod') and config('DIScoGA4.config.transationIdMethod') == "trueOrderId" %}
window.transationIdMethod = "trueOrderId";
{% else %}
window.transationIdMethod= "hashedOrderId";
{% endif %}
</script>
{% if context.customer is not null %}
<span class='d-none ga4-hidden-ads-information'
data-feedcountry='{{ config('DIScoGA4.config.feedCountry') }}'
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>
{% endif %}
{% endif %}
{% endblock %}
{% block disco_meta_extra_information_specialcase %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
if (window.googleAdsEnabled !== true && window.googleAnalyticsEnabled !== true) {
window.ga4Enabled = false;
}
</script>
{% endblock %}
{% endblock %}
{% block disco_meta_extra_information_extensions %}
{% set productsExtension = context.context.extensions.disGA4ProductsExtension %}
{% set lineItemsExtension = context.context.extensions.disGA4LineItemsExtension %}
{% if productsExtension is not null %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4Product = {};
</script>
{% for product in productsExtension %}
{% set price = product.calculatedPrice %}
{% if product.calculatedPrices|length == 1 %}
{% set price = product.calculatedPrices.first %}
{% endif %}
{% set listPrice = price.listPrice %}
{% if listPrice.percentage > 0 %}
{% set listingPrice = price.listPrice.price %}
{% else %}
{% set listingPrice = price.unitPrice %}
{% endif %}
{% set variantText = '' %}
{% if product.variation %}
{% for variation in product.variation %}
{% set variantText = variantText ~ ' ' ~ variation.group ~ ' ' ~ variation.option ~ ' -' %}
{% endfor %}
{% endif %}
{% set seoCategorie = product.seoCategory %}
{% set standardCategories = product.categories %}
{% set ga4Id = 'ga4-product-' ~ product.id %}
{% if product.manufacturer %}
{% set itemBrand = product.manufacturer.translated.name %}
{% else %}
{% set itemBrand = ga4GetManufacturer(product.manufacturerId,context.context) %}
{% endif %}
{% if product.calculatedPrices.count > 0 %}
{% set startPrice = product.calculatedPrices.first.unitPrice %}
{% set hasGraduatedPrice = true %}
{% else %}
{% set startPrice = price.unitPrice %}
{% set hasGraduatedPrice = false %}
{% endif %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4Product['{{ product.id }}'] = {};
window.ga4Product['{{ product.id }}']['item_brand'] = '{{ itemBrand }}';
window.ga4Product['{{ product.id }}']['item_name'] = '{{ product.translated.name }}';
window.ga4Product['{{ product.id }}']['minPurchase'] = '{{ product.minPurchase }}';
window.ga4Product['{{ product.id }}']['shopware_id'] = '{{ product.id }}';
window.ga4Product['{{ product.id }}']['item_id'] = '{{ product.productNumber }}';
window.ga4Product['{{ product.id }}']['realPrice'] = '{{ listingPrice }}';
window.ga4Product['{{ product.id }}']['item_startPrice'] = '{{ startPrice }}';
window.ga4Product['{{ product.id }}']['item_hasGraduatedPrice'] = '{{ hasGraduatedPrice }}';
{% if controllerName|lower == 'product' %}
window.ga4Product['{{ product.id }}']['item_list_id'] = 'product';
window.ga4Product['{{ product.id }}']['item_list_name'] = 'product';
{% elseif controllerName|lower == 'navigation' %}
window.ga4Product['{{ product.id }}']['item_list_id'] = '{{ page.header.navigation.active.id }}';
window.ga4Product['{{ product.id }}']['item_list_name'] = '{{ page.header.navigation.active.name }}';
{% elseif controllerName|lower == 'search' %}
window.ga4Product['{{ product.id }}']['item_list_id'] = 'search';
window.ga4Product['{{ product.id }}']['item_list_name'] = 'search';
{% endif %}
window.ga4Product['{{ product.id }}']['taxRate'] = '{{ product.tax.taxRate }}';
window.ga4Product['{{ product.id }}']['cheapest'] = '{{ price.unitPrice }}';
window.ga4Product['{{ product.id }}']['currency'] = '{{ context.currency.translated.shortName }}';
window.ga4Product['{{ product.id }}']['item_variant'] = '{{ variantText | trim(' ','left') | trim('-','right') }}';
{% if seoCategorie %}
{% set breadcrumbCategories = sw_breadcrumb_full(seoCategorie, context.context) %}
{% set counter = 1 %}
{% for breadcrumbCategory in breadcrumbCategories %}
{% set name = breadcrumbCategory.translated.name %}
{% if counter == 1 %}
window.ga4Product['{{ product.id }}']['item_category'] = '{{ name }}';
{% else %}
window.ga4Product['{{ product.id }}']['item_category{{ counter }}'] = '{{ name }}';
{% endif %}
{% set counter = counter + 1 %}
{% endfor %}
{% elseif standardCategories %}
{% set counter = 1 %}
{% for standardCategory in standardCategories %}
{% set breadcrumbCategories = sw_breadcrumb_full(standardCategory, context.context) %}
{% for breadcrumbCategory in breadcrumbCategories %}
{% set name = breadcrumbCategory.translated.name %}
{% if counter == 1 %}
window.ga4Product['{{ product.id }}']['item_category'] = '{{ name }}';
{% else %}
window.ga4Product['{{ product.id }}']['item_category{{ counter }}'] = '{{ name }}';
{% endif %}
{% set counter = counter + 1 %}
{% endfor %}
{% endfor %}
{% elseif product.categoryTree %}
{% set categories = ga4GetCategories(product.categoryTree,context.context) %}
{% if categories %}
{% set counter = 0 %}
{% for category in categories %}
{% if counter > 0 %}
{% if counter == 1 %}
window.ga4Product['{{ product.id }}']['item_category'] = '{{ category.name }}';
{% else %}
window.ga4Product['{{ product.id }}']['item_category{{ counter }}'] = '{{ category.name }}';
{% endif %}
{% endif %}
{% set counter = counter + 1 %}
{% endfor %}
{% endif %}
{% endif %}
</script>
{% endfor %}
{% endif %}
{% if lineItemsExtension is null %}
{% if page.cart %}
{% set lineItemsExtension = page.cart.lineItems %}
{% endif %}
{% if page.order %}
{% set lineItemsExtension = page.order.lineItems %}
{% endif %}
{% endif %}
{% if lineItemsExtension is not null %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4LineItem = {};
</script>
{% for lineItem in lineItemsExtension %}
{% set fullProduct = ga4GetProduct(lineItem.id,context.context) %}
{% if fullProduct %}
{% set variantText = '' %}
{% if lineItem.payload.options %}
{% for variation in lineItem.payload.options %}
{% set variantText = variantText ~ ' ' ~ variation.group ~ ' ' ~ variation.option ~ '-' %}
{% endfor %}
{% endif %}
{% set categories = ga4GetCategories(fullProduct.categoryTree,context.context) %}
{% set breadcrumbText = '' %}
{% set ga4Id = 'ga4-lineitem-' ~ fullProduct.id %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4LineItem['{{ fullProduct.id }}'] = {};
{% if categories %}
{% set counter = 1 %}
{% for category in categories %}
{% set name = category.name %}
{% if counter == 1 %}
window.ga4LineItem['{{ fullProduct.id }}']['item_category'] = '{{ name }}';
{% else %}
window.ga4LineItem['{{ fullProduct.id }}']['item_category{{ counter }}'] = '{{ name }}';
{% endif %}
{% set counter = counter + 1 %}
{% endfor %}
{% endif %}
{% if fullProduct.manufacturer %}
{% set itemBrand = fullProduct.manufacturer.translated.name %}
{% else %}
{% set itemBrand = ga4GetManufacturer(fullProduct.manufacturerId,context.context) %}
{% endif %}
{% if lineItem.price.taxRules.length > 0 %}
{% set taxes = lineItem.price.taxRules[0].taxRate %}
{% else %}
{% set taxes = 0 %}
{% endif %}
window.ga4LineItem['{{ fullProduct.id }}']['shopware_id'] = '{{ fullProduct.id }}';
window.ga4LineItem['{{ fullProduct.id }}']['item_id'] = '{{ fullProduct.productNumber }}';
window.ga4LineItem['{{ fullProduct.id }}']['item_brand'] = '{{ itemBrand }}' ;
window.ga4LineItem['{{ fullProduct.id }}']['item_name'] = '{{ lineItem.label }}';
window.ga4LineItem['{{ fullProduct.id }}']['item_type'] = '{{ lineItem.type }}' ;
window.ga4LineItem['{{ fullProduct.id }}']['quantity'] = '{{ lineItem.quantity }}';
window.ga4LineItem['{{ fullProduct.id }}']['realprice'] = '{{ fullProduct.calculatedPrice.unitPrice }}';
window.ga4LineItem['{{ fullProduct.id }}']['taxes'] = '{{ taxes }}';
window.ga4LineItem['{{ fullProduct.id }}']['cheapest'] = '{{ fullProduct.calculatedCheapestPrice.unitPrice }}';
window.ga4LineItem['{{ fullProduct.id }}']['item_variant'] = '{{ variantText | trim(' ','left') | trim('-','right') }}';
window.ga4LineItem['{{ fullProduct.id }}']['categories'] = '{{ breadcrumbText | trim('>') }}';
window.ga4LineItem['{{ fullProduct.id }}']['price'] = '{{ checkoutPrice }}';
window.ga4LineItem['{{ fullProduct.id }}']['currency'] = '{{ context.currency.translated.shortName }}';
</script>
{% else %}
<script {% if app.session.get('csp_nonce') %}nonce="{{ app.session.get('csp_nonce') }}"{% endif %} type="text/javascript">
window.ga4LineItem['{{ lineItem.id }}'] = [];
window.ga4LineItem['{{ lineItem.id }}']['shopware_id'] = '{{ lineItem.id }}';
window.ga4LineItem['{{ lineItem.id }}']['item_id'] = '{{ lineItem.payload.productNumber }}';
window.ga4LineItem['{{ lineItem.id }}']['item_name'] = '{{ lineItem.label }}';
window.ga4LineItem['{{ lineItem.id }}']['type'] = '{{ lineItem.type }}' ;
window.ga4LineItem['{{ lineItem.id }}']['quantity'] = '{{ lineItem.quantity }}';
window.ga4LineItem['{{ lineItem.id }}']['price'] = '{{ lineItem.price.totalPrice }}';
window.ga4LineItem['{{ lineItem.id }}']['taxes'] = '{{ lineItem.price.taxRules[0].taxRate }}';
</script>
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}
{% block disco_hidden_line_items_information %}
{% if page.cart %}
{% set discocart= page.cart %}
{% set discolineItems = page.cart.lineItems %}
<div class="d-none discoga4-header-hidden-line-items-information"
data-currency="{{ context.currency.translated.shortName }}"
data-shipping="{{ discocart.deliveries.shippingCosts.sum().totalPrice }}"
data-value="{{ discocart.price.totalPrice }}"
data-tax="{{ discocart.price.calculatedTaxes.amount }}"
>
{% endif %}
{% if page.order %}
{% set discocart= page.order %}
{% set discolineItems = page.order.lineItems %}
<div class="d-none discoga4-header-hidden-line-items-information"
data-currency="{{ context.currency.translated.shortName }}"
data-shipping="{{ discocart.shippingTotal }}"
data-value="{{ discocart.price.totalPrice }}"
data-tax="{{ discocart.price.calculatedTaxes.amount }}"
>
{% endif %}
{% if discocart %}
{% for lineItem in discolineItems %}
{% if lineItem.priceDefinition.price %}
{% set gaPrice = lineItem.priceDefinition.price %}
{% else %}
{% set gaPrice = lineItem.price.totalPrice %}
{% endif %}
{% block disco_hidden_line_item_information %}
<span class="hidden-line-item"
data-id="{{ lineItem.id }}"
data-name="{{ lineItem.label }}"
data-type="{{ lineItem.type }}"
data-sku="{{ lineItem.payload.productNumber }}"
data-quantity="{{ lineItem.quantity }}"
data-price="{{ gaPrice }}">
</span>
{% endblock %}
{% endfor %}
</div>
{% endif %}
{% endblock %}
{% endblock %}