{% if not url %}
    {% set activeMethod = __SELF__.activeMethod.only('code', 'name') %}
    <script>
        $(function () {
            window.dataLayerData = dataWithMethod({{ activeMethod | json_encode | raw }})
            $.subscribe('mall.cart.paymentMethodChanged', function (e, data) {
                window.dataLayerData = dataWithMethod(data.method)
            })

            function dataWithMethod (method) {
                var dl = {{ dataLayer | json_encode | raw }};
                dl.ecommerce.checkout.actionField = {step: 1, method: method.code}
                return dl
            }
        })
    </script>
    <div id="mall-datalayer"></div>
{% else %}
    <script>
        var redirect = function () {
            document.location = '{{ url }}'
        }
        window.dataLayerData.eventCallback = redirect
        setTimeout(redirect, 500)

        dataLayer.push(window.dataLayerData)
    </script>
{% endif %}
