Search
Close this search box.
Search
Close this search box.

How to add adwords conversion tag in WordPress

Step 1: Setup conversions in your AdWords account

  1. Sign in to your Google Ads account.
  2. In the upper right corner, click the tools icon , and under Measurement, click Conversions.
  3. Click the plus button.
  4. Click Website.
  5. In Category tick the Purchase radio button.
  6. Give a Conversion name.
  7. Give a value (eg. 5 euros).
  8. In count select Every.
  9. In conversion window give 90 days.
  10. In Tag setup select the Install the tag yourself.
  11. In Global site tag select the The global site tag isn’t installed on all your HTML pages.
  12. In event snippet select the Page load.

Step 2: Install a plugin to insert the scripts

You can install the Head, Footer and Post Injections plugin to do so.

Step 3: Insert the global site tag in the head

First, you must add the global site tag in the head. To do so, go to Settings > Header and Footer. In the Head and Footer tab, inside the Head page section (for every page), insert the code below (with your own tags).

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

gtag('config', 'UA-XXXXXXX-X');
gtag('config', 'AW-XXXXXXXXX');
</script>

Step 4: Verify that all good until here

You can use the Google tag assistant.

Step 5.1: Case 1: Track WooCommerce conversions

WooCommerce does not include a thank you page which makes it a little more challenging to embed tracking events for things like Google Tag Manager and AdWords.

The code snippet below will allow you to track orders in Google along with the order ID and Order Total. This snippet should be placed in your WordPress theme’s functions.php file with the “XX-XXXXXXXXX” and the “ZZZZZZZZZZ” replaced with your own unique values from Google.

add_action('woocommerce_thankyou', 'woocommerce_thankyou_adwords_conversions');

function woocommerce_thankyou_adwords_conversions() {
    if (!$order_id)
        return;
    $order = wc_get_order($order_id);
    if ($order) {
        $order_id = $order->get_id();
        $order_total = $order->get_total();
    ?>
    <!-- Event snippet for Purchase conversion page -->
    <script>
        gtag('event', 'conversion', {
                'send_to': 'XX-XXXXXXXXX/ZZZZZZZZZZ',
                'value': '<?= $order_total ?>',
                'currency': 'EUR',
                'transaction_id': '<?= $order_id ?>'
            });
    </script>
    <?php
    }
}

Step 5.2: Case 2: Create a Conversion Page for forms

There are a lot of different ways to track conversions, but one of the most common ones is tracking contact form submissions. This allows you to know how many leads you get each week and what ads are generating those leads. The easiest way to do that is to use a “thank you” page.

Step 5.2.1

The first thing you need to do is create a “thank you” page in WordPress. Under Pages in your WordPress dashboard click on “Add New” and create a “thank you” page. This can be named whatever you want. But remember, this is what people will see after they fill out a contact form. Ensure the permalink (URL) is domain.com/thank-you/ as we will be using this later on.

Then fill out the page description with what you want them to see. In our example you can see we simply let them know that we will be in touch soon.

Open the text editor and insert the code snippet (it willi be something like that):

<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-XXXX/XXXXX',
      'value': 1.0,
      'currency': 'EUR'
  });
</script>

Then publish the page when you are ready.

Step 5.2.2

Next we need to have your contact form redirect to your thank you page after someone fills it out. You can do this in the settings of popular contact form plugins. We have listed a couple example configurations below. You can also accomplish this with JavaScript action hooks and no redirects, but for those just starting out with conversion tracking a redirect works fine and is simple to setup.

Contact Form 7

Add this code in your funtions.php:

add_action( 'wp_footer', function () { ?>
<script>
document.addEventListener('wpcf7mailsent', function( event ) {
location = 'https://wpdev.ink/thank-you/';
}, false );
</script>
<?php } );

Gravity Forms

To add a redirect in the Gravity Forms plugin, click “Edit” on your form and click into the “Confirmations” tab. You can then select “Redirect” as an option and input your URL.

Step 5.2.3

Submit your form and use google tag assistant to see that it works.

Learning resources