1

Hope someone can help me with this. It's very easy to do I bet, I'm just not used to magento yet.

I'm adding Google Ads to my magento (1.9).. I need to add this script code:

<!-- Event snippet for ads page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-8xxxxxxxxxxxxxxxxxx',
      'value': 1.0,
      'currency': 'USD',
      'transaction_id': ''
  });
</script>

only in "order success" page (which is success.phtml). It has to be in Head. I know that I can't just add the code in success.phtml file. From my research, I have to mess with layout/local.xml file.

Could someone explain to me how to do this? Much appreciate!

1

You should create frontend/active_theme/layout/local.xml in your theme. And should have this code:

<?xml version="1.0"?>
<layout version="0.1.0">
     ..........
     ........
     <checkout_onepage_success translate="label">
        <reference name="head">
            <block type="core/text" name="header_module" as="header_module">
                <action method="setText">
                    <text><![CDATA[<script>gtag('event', 'conversion', {
                            'send_to': 'AW-8xxxxxxxxxxxxxxxxxx',
                            'value': 1.0,
                            'currency': 'USD',
                            'transaction_id': ''
                    });</script>]]></text>
                </action>
            </block>
        </reference>
    </checkout_onepage_success>
    .............
    ...............
</layout>

This should add the script to head of your success page.

| improve this answer | |

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.