I'm trying to add tracking code to my onepage success page. I've created layout and created success.phtml to my custom theme. app/design/frontend/my_theme/Magento_Checkout/layout/checkout_onepage_success.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <script src="module-checkout::templates/success.phtml"/>


my tracking code

Everything fine but the tracking code didn't appear when I click view page source in my browser !

Could you please help me.

1 Answer 1

  1. You cannot use something like View Page Source for Success page, because the browser will try to load page one more time for receive source and will redirect to cart or home page instead. You can use Inspect logic or use temporary workaround from https://magento.stackexchange.com/a/357279/91782

  2. You have incorrect layout definition. Looks like you are trying to add phtml block, but using script directive for. You need something like:

    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            <referenceContainer name="after_body_start">
                <block class="Magento\Checkout\Block\Onepage\Success" name="your_tracking_code" template="Magento_Checkout::success.phtml" cacheable="false"/>

    Where I suggest to create custom block instead of Magento\Checkout\Block\Onepage\Success to receive current order data. See Magento\Checkout\Block\Onepage\Success as example how to receive current order data. You should define custom template instead of Magento_Checkout::success.phtml in the same format.

    I hope you can see some manuals or example in Magento code

  • Thanks a lot victor, but I found the solution. there is another success.phtml in Magento_InventoryInStorePickupFrontend and that was the file which I've to update
    – Dun7ill
    Aug 7, 2022 at 8:51

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.