December 28, 2024
3 min read

Are you running an online store with WooCommerce and want to track conversions from your Google Ads campaigns? Implementing Google Ads conversion tracking on your WooCommerce store can help you measure the effectiveness of your advertising efforts and optimize your campaigns for better results.

This tutorial will guide you through setting up Google Ads conversion tracking on your WooCommerce store using a custom PHP code snippet. This code will allow you to send conversion data to Google Ads when a customer completes a purchase on your site.

Prerequisites

Before we begin, make sure you have the following:

  • A WordPress website with WooCommerce installed and properly configured.
  • Access to your Google Ads account.

Step 1: Create a Google Ads Conversion Action

If you haven’t already, you need to set up a conversion action in your Google Ads account. Here’s how:

  • Log in to your Google Ads account.
  • Click on “Tools & Settings” and then “Conversions” in the left sidebar.
  • Click the “+ New Conversion” button.
  • Follow the prompts to create a new conversion action. Make note of the conversion ID and label.

Step 2: Add Custom Code

Now, you’ll need to add a custom PHP code snippet to your WordPress site. This code will trigger the Google Ads conversion tracking when a customer completes a purchase. You can add this code to your theme’s functions.php file or create a custom plugin.

functions.php
<?php

add_action( 'woocommerce_thankyou', 'mukto_google_conversion_tracking' );

function mukto_google_conversion_tracking( $order_id ) {
    // Get the order object
    $order = wc_get_order( $order_id );
    $order_data = $order->get_data();
    $order_billing_phone = $order_data['billing']['phone'];
    $order_billing_name = $order_data['billing']['first_name'] . ' ' . $order_data['billing']['last_name'];
    $order_total = $order_data['total'];

    echo "<script>
        gtag('event', 'conversion', {
            'send_to': ''AW-123456789/xxxxxxxxxx'',
            'transaction_id': '" . $order_id . "',
            'amount_paid': '" . $order_total . "',
            'customer_phone': '" . $order_billing_phone . "',
            'customer_name': '" . $order_billing_name . "'
        });
    </script>";
}

In this code:

  • We’re using the woocommerce_thankyou action hook to trigger the conversion tracking code when a customer reaches the WooCommerce thank you page after a successful purchase.
  • The order data is retrieved, including the order ID, billing phone, billing first name, billing last name, and total amount paid.
  • The Google Ads gtag script is called with the necessary parameters, including the conversion ID and label you obtained in Step 1.

Make sure to replace 'AW-123456789/xxxxxxxxxx' with your actual conversion ID and label.

Step 3: Add Google Tag Manager Script

To complete the implementation, you need to add the Google Tag Manager (gtag.js) script to the head section of your website. Add the following code snippet just before the closing </head> tag in your WordPress theme’s header.php file or use a plugin that allows you to add code to the head section:

header.php
<!-- Google Tag Manager (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-11306771618"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'AW-123456789');
</script>

his script will initialize the Google Tag Manager and configure it with your Google Ads conversion ID.

Step 4: Test and Verify

After adding the code, it’s essential to test your checkout process to ensure that the conversion tracking is working correctly. Make a test purchase on your website, and then check your Google Ads account for conversion tracking data.

Conclusion

Implementing Google Ads conversion tracking on your WooCommerce store allows you to measure the success of your advertising campaigns accurately. By following the steps outlined in this tutorial and adding the provided custom code and Google Tag Manager script, you can start tracking conversions and optimizing your Google Ads campaigns for better ROI.

Remember to regularly monitor your Google Ads account to assess the performance of your campaigns and make data-driven decisions to improve your online store’s profitability.

Happy tracking and selling!

Leave a Reply

Your email address will not be published. Required fields are marked *

Create a new WordPress administrator via functions.php & FTP

Sometimes, you might need to create an administrator account in WordPress without being able to access the admin dashboard. This could be because you have lost access to your site’s admin panel or when troubleshooting a client’s website. In this tutorial, we will show you how to programmatically add a WordPress administrator account using the […]

Cookie Popup with jQuery

Browser cookies popup accept, store cookies in browser with jQuery

Remove Website field from WordPress comment & Change cookies remember text

Remove Website field from WordPress comment & Change cookies remember text to Remember me!

Remove WooCommerce checkout fields

Remove WooCommerce Checkout field with simple filter hook

Web Development Project in mind?

if you looking for a web developer for paid contribution to your project I am available for work.

Mukto
Mukto

Click the button below to chat with me.