Adding Google Remarketing Tags in Magento: A Comprehensive Guide
If you’re an e-commerce business owner or developer looking to implement Google remarketing on your Magento site, you’ve landed in the right place. In this guide, we’ll walk through the process of adding the remarketing tag step-by-step and ensure it’s correctly placed before the closing </body> tag.
Understanding Magento’s Template System
Magento uses a template system based on XML files to define page layouts. The default layout for your store is defined in the app/design/frontend/base/default/layout directory. However, we recommend creating a custom theme for your modifications to avoid losing changes during updates.
For this example, let’s assume you have created a custom theme named “mytheme” under the app/design/frontend/mytheme/mytheme folder.
Accessing the Correct Template File
The body of your Magento store is defined in the template file located at:
app/design/frontend/{your_package}/{your_theme}/template/page/html/head.phtml
Here, {your_package} and {your_theme} should be replaced with the package and theme names you’re using (e.g., “mytheme”).
Adding the Remarketing Tag
To add the remarketing tag, open the app/design/frontend/{your_package}/{your_theme}/template/page/html/head.phtml file in your favorite text editor.
Locate the line that reads:
</body>
Before this line, paste the following Google remarketing code snippet. Replace INSERT_YOUR_CONVERSION_ID_HERE with your actual conversion ID:
<!-- Remarketing tags -->
<script type="text/javascript">
// <![CDATA[
var google_conversion_id = INSERT_YOUR_CONVERSION_ID_HERE;
// ]]>
</script>
<script type="text/javascript"
src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/INSERT_YOUR_CONVERSION_ID_HERE/?value=0&currency_code=CAD&label=INSERT_YOUR_LABEL_HERE&guid=ON&script=0"/>
</div>
</noscript>
<!-- End Remarketing tags -->
Ensure the entire snippet is placed immediately before the </body> tag.
Testing Your Integration
After saving the changes, flush your Magento cache:
php bin/magento cache:flush
Then, open your store’s homepage in a web browser to verify that the remarketing script has been successfully loaded.
Conclusion
Adding Google remarketing tags to Magento requires a basic understanding of the template system and proper file navigation. By following this guide, you’ve now learned how to:
- Locate the correct
head.phtmlfile for your custom theme. - Identify the precise position before the closing
</body>tag. - Paste the remarketing script in the appropriate location.
Remember that it’s always a good practice to create a child theme rather than modifying the core files directly. This approach ensures your changes persist across updates and keeps your store’s codebase clean.
If you’re looking for more advanced Magento customizations or need further assistance with Google remarketing, consider reaching out to our team at Laravel Company. We offer professional development services to help businesses like yours maximize their e-commerce potential.