How to add conversion tracking code to thank you confirmation page only

Highlighted
New Member
6 0 0

Hi All!
Anyone looking to add conversion tracking to the confirmation page only, please use the following:

    <script type="text/javascript">
      if(Shopify.Checkout.step === 'thank_you')
      {

        /* Start Tracking Code */
        gtag('event', 'conversion', {
            'send_to': 'AW-xxxx/xxxx',
            'currency': 'USD',
            'transaction_id': '{{ checkout.id }}',
            'value': "{{ checkout.total_price | money_without_currency }}"
        });

        /* End Tracking Code */
      }
    </script>

We are on Shopify plus. I'm not sure if this will work on other tiers of Shopify.

Hopefully, this helps someone.

Thanks,

- Jarett

0 Likes
Highlighted
Shopify Expert
218 0 11

Hi Jarett

Have you tried going to settings -> Checkout. In the order processing section, there's a box 'Additional Scripts' 

You don't need the if statement, just the tracking code. 

This page might help you: https://help.shopify.com/manual/orders/status-tracking/add-conversion-tracking-to-thank-you-page

If you need help with a Shopify customisation, drop me an email on pipparose@etempa.co.uk
0 Likes
Highlighted
New Member
6 0 0

Hi Pippa!

I did, but the conversion tracking fired throughout the whole process and we only wanted it to fire on the confirmation page.

0 Likes
Highlighted
Shopify Expert
218 0 11

That sounds really weird. I've just done a test on a test store and my script only fired on the thank you page. 

The order status page can be accessed multiple times ie a customer returning to check the order status. You can add the following around your script to ensure it only fires once. 

{% if first_time_accessed %}
  <!-- Conversion scripts you want to run only once -->
{% endif %}

Or, it might be the problem is elsewhere. If you add the below to the additional scripts box, then run through your checkout process, right click anywhere on the page and click inspect element. This should bring up a window which will have a 'Console' tab. If you see the word 'Test' appear in the console before you get to the order confirmation page, we know it's firing too early. But what should happen is you only see it appear on the order confirmation page. 

<script>console.log('test');</script>

If you need help with a Shopify customisation, drop me an email on pipparose@etempa.co.uk
0 Likes
Highlighted
New Member
6 0 0

I've done this before and the script fired through all steps. I'm just providing another option for anyone who may be having issues with this. 

0 Likes
Highlighted
New Member
6 0 0
Highlighted
Shopify Expert
218 0 11

Hmm, I'm not sure then. Without looking and testing it directly I might not be able to fix this one. Feel free to drop me an email if you want further help with this, or someone else on the forum might be able to shed some light? 

And no problem, I'll take a look at your other post. 

If you need help with a Shopify customisation, drop me an email on pipparose@etempa.co.uk
0 Likes
Highlighted
New Member
1 0 0

Hi, I am having same problem as well. 

I added my code on Setting>Checkout> Additional Script, code as below.

 

<!-- Global site tag (gtag.js) - Google Ads: 630666293 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-630666293"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'AW-630666293');
</script>

<!-- Event snippet for Website sale conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': 'AW-630666293/NCIgCLaRg9EBELXo3KwC',
'value': {{ checkout.total_price | money_without_currency }},
'currency': 'USD',
'transaction_id': '{{ order.order_number }}’.
});
</script>

 

And then I added this code at theme.liquid 

But ended up I think it just fired all around, this caused my Google Ads getting messy.

I got no sales at all but my conversion shoot up way high to 700% within few days. 

Can any advise on this ? I am really headache on this. 

Thanks 

0 Likes