I need to add a script that tracks orders on a Magento shop. This script is to be inserted onto the order confirmation page. What is the easiest way of inserting this script onto the order confirmation page in Magento?

The script looks like this: <script>_mktz.push(['_Goal','sale','VALUE',{transaction:'REPLACE_WITH_YOUR_ID'}]);</script>

Is it possible to do this through the backend, or is it necessary with FTP access?

And further more i need to insert variables for the total order value (VALUE) and the transaction ID (REPLACE_WITH_YOUR_ID). How would i go about extracting these two variables the easiest way possible?

I apologize if similar questions have been answered before, but I did not quite find them to any use in regards to my specific case.

Thank you in advance.

  • Is this Magento 1 or 2? – rain2o Apr 11 at 12:38
  • It's Magento 1 :) – LENide300_KK Apr 11 at 12:53
  • Ah, just saw this after I posted with M2 answer... I'll see if I can remember enough about M1 to update my answer. – rain2o Apr 11 at 12:58

The answer will vary depending on if it's Magento 1 or 2, but only slightly. I will assume Magento 2 for now.

UPDATE - After answering for Magento 2 the OP updated that it's M1. I will leave the M2 answer below and add my response for M1.

Magento 1

There are a few answers out there that can help. This will help you customize your success page template - How to customize checkout success page.

And this provides a couple of options for adding the script - Help with adding script codes between <head></head> in success.phtml.

Ultimately you will need to either inject in the layout or add to the success.phtml file in your theme.

As for adding the order values, this answer seems to provide information on how to get the Order ID and the Order Total - https://stackoverflow.com/questions/9062167/add-total-price-in-checkout-success-page.

Magento 2

You will need to do this in your theme from a phtml file. You can either create your own block or add to an existing block.

If you want to add to an existing block then either create or edit the file in your theme app/design/frontend/{your_vendor_name}/{your_theme_name}/Magento_Checkout/templates/success.phtml. You can add your script directly in there.

If you want to create your own template to hold this script then you'll have to add a block in app/design/frontend/{your_vendor_name}/{your_theme_name}/Magento_Checkout/layout/checkout_onepage_success.xml something like this.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="content">
            <block class="Magento\Checkout\Block\Onepage\Success" name="checkout.success.tracking" template="Magento_Checkout::tracking.phtml" cacheable="false" />

Then create the file app/design/frontend/{your_vendor_name}/{your_theme_name}/Magento_Checkout/templates/tracking.phtml and add your script in there.

Now, as for getting the values you need the Order Id is available to the Success block, but I don't think the order value is by default. To get the order ID just run $block->getOrderId() in the template. To get the order value you'll have to add it to the block data. Probably the best approach is to create a custom block that extends the success block and use that instead.

  • Thanks for the reply. It is in Magento 1, sorry for not writing that in my original title. Will this change anything? And I was hoping i could do this without FTP access and just directly through the backend. But this is not possible then, I assume? – LENide300_KK Apr 11 at 13:03
  • I just updated it with some info for Magento 1 too. – rain2o Apr 11 at 13:03
  • Oh alright sweet, thanks! Just saw that right after i had posted my comment :-) – LENide300_KK Apr 11 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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