WooCommerce Google Ads: Add to Cart Event with Google Tag Manager

4 min read 15 hours ago
Published on Dec 26, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, you will learn how to set up the Add to Cart event for your WooCommerce store using Google Tag Manager (GTM) and Google Ads. This setup is crucial for tracking e-commerce conversions effectively and optimizing your advertising campaigns. By the end of this guide, you'll have accurate tracking in place to enhance your online store's performance.

Step 1: Ensure Proper Access

Before you begin, make sure you have the necessary permissions and access:

  • Admin access to your WooCommerce store.
  • Access to Google Tag Manager and Google Ads accounts.

Step 2: Set Up Google Tag Manager Container

  • Sign in to your Google Tag Manager account.
  • Create a new container for your WooCommerce store.
  • Choose "Web" as the target platform and click "Create."

Step 3: Install GTM Plugin on WordPress

  • Go to your WordPress dashboard.
  • Navigate to the Plugins section and click "Add New."
  • Search for "Google Tag Manager for WordPress" and install the plugin.
  • Activate the plugin after installation.

Step 4: Add GTM Container ID

  • In your GTM account, find your Container ID (formatted as GTM-XXXXXX).
  • Go back to your WordPress dashboard and access the settings of the GTM plugin.
  • Enter your GTM Container ID in the appropriate field and save changes.

Step 5: Verify GTM Container Installation

  • Use the GTM preview mode to check if the container is installed correctly.
  • Visit your WooCommerce store and ensure that the GTM script is visible in the page source.

Step 6: Create Conversion Action in Google Ads

  • Sign in to your Google Ads account.
  • Navigate to the "Tools & Settings" menu and select "Conversions."
  • Click on the "+" button to create a new conversion action.
  • Choose "Website" and fill in the necessary details such as conversion name, value, and count.

Step 7: Enable Data Layer in WooCommerce

  • Add the necessary code to your WooCommerce theme to enable the data layer.
  • This typically includes adding the following code snippet to your functions.php file:
add_action('wp_footer', function() {
    ?>
    <script>
        dataLayer = [{
            'event': 'addToCart',
            'ecommerce': {
                'add': {
                    'products': [{
                        'name': '<?php the_title(); ?>',
                        'id': '<?php echo get_the_ID(); ?>',
                        'price': '<?php echo get_post_meta(get_the_ID(), '_price', true); ?>',
                        'category': '<?php echo get_the_terms(get_the_ID(), 'product_cat')[0]->name; ?>',
                        'quantity': 1
                    }]
                }
            }
        }];
    </script>
    <?php
});

Step 8: Test Add to Cart Event

  • Use the GTM preview mode to test the Add to Cart event.
  • Add a product to your cart on the website and check the data layer for the event.

Step 9: Set Up Conversion Linker Tag

  • In GTM, create a new tag and select "Conversion Linker."
  • Configure it to fire on all pages to ensure accurate tracking across your site.

Step 10: Create Custom Event Trigger

  • Create a new trigger in GTM for the Add to Cart event.
  • Set the trigger type to "Custom Event" and name it "addToCart."

Step 11: Add Google Ads Conversion Tracking Tag

  • Create a new tag in GTM and choose "Google Ads Conversion Tracking."
  • Enter your conversion ID and label from Google Ads.
  • Set the trigger to the custom event you created earlier for Add to Cart.

Step 12: Create Remarketing Tag

  • Create another tag in GTM for Google Ads Remarketing.
  • Configure it to fire on all pages or specific pages as per your remarketing strategy.

Step 13: Final Testing and Verification

  • Use GTM preview mode again to test all tags and triggers.
  • Ensure that your conversion and remarketing tags are firing correctly when products are added to the cart.

Step 14: Publish Changes

  • Once everything is tested and verified, publish your changes in Google Tag Manager.

Conclusion

You have successfully set up the Add to Cart event tracking for your WooCommerce store using Google Tag Manager and Google Ads. This setup will help you monitor conversions and optimize your advertising efforts effectively. As a next step, consider analyzing your data to refine your marketing strategies further.