Skip to content

Magento 2 variables

Google team share with me a script for tracking and they asked me to put magento 2 variables.
I’ve searched about and this is the script after update but I think it’s not correct.

<script>
  dataLayer.push({
    'event':'purchase',
    'order_value':$order->getGrandTotal(),
    'order_id':$order->getOrderId(),
    'enhanced_conversion_data': {
      "email": $customer_email,   
      "phone_number": $telephone_tmp,
      "first_name": $firstname,
      "last_name": $lastname,
      "street": $address_tmp,
      "city": $city,
      "postal_code": $postal,
      "country": $country
    }
  })
</script>

Could you please help me.