Hello,
I am trying to set Google Ads but i don't where i have to insert this code.
I am not sure if this is the success.phtml
May i get help please ?
<script>
window.dataLayer = window.dataLayer || [];
var shipping_price = '{{shipping_price | money_without_currency
}}';
shipping_price = shipping_price.replace(",", ".");
var total_price = '{{total_price | money_without_currency }}';
total_price = total_price.replace(",", ".");
var tax_price = '{{tax_price | money_without_currency }}';
tax_price = tax_price.replace(",", ".");
var orderItemsName = []
var orderItemsPrice = []
var orderItemsQuantity = []
var orderItemsId = []
var totalQuantity = 0;
{% for line_item in line_items %}
orderItemsName.push( '{{ line_item.product.title | remove: "'" |
remove: '"'}}')
orderItemsPrice.push('{{ line_item.price | times: 0.01 }}');
orderItemsQuantity.push('{{ line_item.quantity }}');
orderItemsId.push('{{ line_item.product_id }}');
totalQuantity += {{ line_item.quantity }};
{% endfor %}
{% if first_time_accessed %}
window.dataLayer.push({
'page_type': 'purchase',
'event': 'purchase_chpx',
'currency': "{{ shop.currency }}",
'totalValue': total_price,
'shipping': shipping_price,
'tax': tax_price,
'payment_type': '{{order.transactions[0].gateway}}',
'transaction_id': "{{order.name}}",
'email': "{{ checkout.customer.email }}",
'phone_number': "{{billing_address.phone}}",
'first_name': "{{ checkout.customer.first_name }}",
'last_name': "{{ checkout.customer.last_name }}",
'street': "{{ shipping_address.address1 }}",
'city': "{{ shipping_address.city }}",
'region': "{{ shipping_address.province }}",
'postal_code': "{{ shipping_address.zip }}",
'country': "{{ shipping_address.country }} ",
'productName': orderItemsName,
'productPrice': orderItemsPrice,
'productQuantity': orderItemsQuantity,
'productId': orderItemsId,
});
{% endif %}
</script>
Regard
Hello @contactcom3bd1
You don't need to add it in any file. you can simply use the System->Configuration->Design->HTML Head->Miscellaneous Scripts section in the config and add your code int here. It will be visible in all the pages.
Thank you
Hi @contactcom3bd1 ,
Based on your script details I am assuming you need to pass order data so you can easily get all information in success.phtml
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
From above $order object you need to get all information and pass it in your script like below.
<script>
window.dataLayer = window.dataLayer || [];
var shipping_price = '<?php echo $order->getShippingAmount(); ?>';
Problem Solved? Accept as Solution!
Hope it helps!
Thanks