How To Implement Google Ads Conversion Tracking In WooCommerce | Code For Developers

How to Implement Google Ads Conversion Tracking in WooCommerce

Learn how to add Google Ads tracking code to your WooCommerce thank you page effortlessly, without the need for plugins.

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!

Previous Code

Random slide order in slick sider

Change slick carousel slide order randomly ...

Next Code

Customizing WooCommerce Order Numbers with Prefix and Year Suffix

Customize WooCommerce order numbers your way, whet ...

Leave a Reply

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

If you find it useful

Buy me a coffee

ACF

Elementor

JavaScript

jQuery

Others

PHP

WooCommerce

WordPress

WP Plugin Dev

Remove WooCommerce checkout fields

Remove WooCommerce Checkout field with simple filt ...

Making Specific Products Unpurchasable or purchasable for a specific date in WooCommerce

How to make specific products not purchasable in W ...

Customizing WooCommerce Order Numbers with Prefix and Year Suffix

Customize WooCommerce order numbers your way, whet ...

Implementing WooCommerce Shop Page Quantity Input and Plus (+) Minus (-) Button with simple Code

Enhance the user experience on your WooCommerce we ...

Add an additional custom checkbox in the WooCommerce checkout

Add an additional custom checkbox after the terms ...

top