Skip to content

Adding tracking code to success page

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">
<head>
    <script src="module-checkout::templates/success.phtml"/>
</head>

app/design/frontend/my_theme/Magento_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.