create these layout files in your module.
Step 1.
view/frontend/layout/my_tracking_code.xml
- feel free to rename this one.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="before.body.end">
<block ...... />
</referenceContainer>
</body>
</page>
Step 2.
...and these ones (keep the name this time)
checkout_index_index.xml
, checkout_onepage_success.xml
contact_index_index.xml
.
All of them should have this content:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="my_tracking_code"/> <!-- make sure the value of the "handle" attribute matches the name of the file you created in step 1. -->
</page>