type:
integration
supports-foxycart-version-from:
2.0
system:
Google Adwords
name:
Google Adwords
description:
Integrate Google Adwords with your FoxyCart receipt
tags:
Google, Adwords
date:
2015-10-01

Google Adwords

Please note: The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please post in our forum, but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.

Installation

Step 1: Create Adwords Action

Follow the steps detailed on this page for getting your Google Adwords integration code. For step 7 in part 1 on that page, select the “Use different values for each conversion” option.

Once you complete the steps, you'll be offered choices on how you want to set up the tag. Select “Install the tag yourself”.

Step 2: Install Adwords Tag

Global Site Tag

This will provide you with some instructions for installing the Global Site Tag first off. Complete that section for your needs. Unless you've already included the Global Site Tag within your Foxy templates or configuration, you'll select “The global site tag isn't installed on all your HTML pages” here.

Copy the code shown to you based on your selection into the “header” textarea of the “Add custom header and footer code to your templates” option, as found on the “configuration” section of the Foxy administration.

Event Snippet

In the next section for the Event Snippet, leave the default selection as Page Load. Copy the code shown here into the “header” textarea of your configuration too. The code will look something like this:

<!-- Event snippet for Test Ecommerce conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AA-11111111/AAAAAAAA1A11AAAA1A',
      'value': 25.0,
      'currency': 'USD',
      'transaction_id': ''
  });
</script>

Modify the script to update the value, currency and transaction_id parameters to pull the dynamic data from your receipt using FC.json.total_order, FC.json.locale_info.int_curr_symbol.trim() and FC.json.transaction_id respectively. Also, wrap the gtag event in a javascript if conditional to only output the conversion event on the first time the receipt is loaded, and only if it's not an updateinfo or subscription cancellation - that will look like this:

if (FC.json.first_receipt_display && !FC.json.is_updateinfo && !FC.json.is_subscription_cancel) {
    // gtag event code here
}

The resulting snippet should look something like this:

<!-- Event snippet for Test Ecommerce conversion page -->
<script>
  if (FC.json.first_receipt_display && !FC.json.is_updateinfo && !FC.json.is_subscription_cancel) {
      gtag('event', 'conversion', {
          'send_to': 'AA-11111111/AAAAAAAA1A11AAAA1A',
          'value': FC.json.total_order,
          'currency': FC.json.locale_info.int_curr_symbol.trim(),
          'transaction_id': FC.json.transaction_id
      });
  }
</script>

Use the above just as a reference - ensure that the send_to value above correctly matches what the Google Ad set up page shows you.

Site Tools