2

I am trying to implement a Google Tag from the PPC account of my clients. This code is on my sales conversion page. I believe I am along the right lines, but I'm not confident my PHP will pull in the correct Magento data.

I wish to insert the Value of the conversion and the Transaction ID.

<!-- Event snippet for Sales conversion page -->
<?php 
  $order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
  $adwords_saleamt = $order_details->subtotal;
  $transaction = Mage::getModel('sales/order_payment_transaction');
  $transaction_id = $transaction->setOrderId(1); 
?>
<script>
  gtag('event', 'conversion', {
  'send_to': 'XX-XXXXXXXXX/XXXXXXXXXXXXXX',
  'value': '<?php echo $adwords_saleamt; ?>',
  'currency': 'GBP',
  'transaction_id': '<?php echo $transaction_id; ?>'
});
</script>
1
  • Hey can u tell me what value you are getting in $adwords_saleamt? Sep 20, 2018 at 3:56

1 Answer 1

0

please try this code

<?php
$OrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$Order = Mage::getModel('sales/order')->load($OrderId);
$incrementId = $Order->getIncrementId();
?>

<script>
 gtag('event', 'conversion', {
   'send_to': 'XX-XXXXXXXXX/XXXXXXXXXXXXXX',
   'value': <?php echo number_format($Order->getSubtotal(),2,".",""); ?> ,
   'currency': 'GBP',
   'transaction_id': <?php echo "'".$incrementId."'"; ?>
 });

</script>
5
  • Thank very much for the response, testing now. Sep 20, 2018 at 7:46
  • please let me know
    – Altravista
    Sep 20, 2018 at 8:06
  • Hi, so, two weeks later, and the ppc company are telling me the code is recording a transaction but isn't recording a value? Some further help would be very much appreciated. Oct 4, 2018 at 13:42
  • have you use my code? can you make a test order and see the thank you page source code and verify script result for value var?
    – Altravista
    Oct 4, 2018 at 14:50
  • I used your code yes. I'll find out how to make a test order to verify the script Oct 4, 2018 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.