Google Ads Custom Variables
- Added support for Google Ads Custom Variables
New feature
Google Ads allows you to track Custom Variables with each conversion.
With version 1.43.5
of the Pro version of the Pixel Manager we added support for Custom Variables for Google Ads for purchase conversion events.
(Currently only available for subscribers of the beta version 1.43.5-beta.2
and will be available for all users once version 1.43.5
is released.)
What are Custom Variables?
Let's say you want to see conversion numbers split by the color of the product. You can add a custom variable color
to the purchase conversion event.
Or, you want to see conversion numbers split by the product name. You can add a custom variable product_name
to the purchase conversion event.
Or, you want to see conversion numbers split by the product category. You can add a custom variable category
to the purchase conversion event.
This helps you answer questions like:
- Which color converts the best?
- Which product category converts the best?
- Which product name converts the best?
How to add Custom Variables to the purchase conversion event
Because we want to give you full flexibility, we added a filter to the Pixel Manager.
With the following filter you can add Custom Variables to the purchase conversion event:
add_filter('pmw_google_ads_order_custom_variables', function ($custom_variables, $order) {
$custom_variables['example_variable'] = 'example_string';
$custom_variables['color'] = 'example_blue';
$custom_variables['product_name'] = 'example_name';
return $custom_variables;
}, 10, 2);
Or head over to the setup guide for Google Ads Custom Variables to learn more.
Examples
Track Google Automated Discounts
If you're using Google Automated Discounts, and use our Google Ads integration for Google Automated Discounts, you can track which conversions came from Google Automated Discounts.
The following example is still experimental and might change in the future without notice.
/**
* Adds a custom variable to Google Ads order data based on
* Google Automated Discounts session status.
*
* This filter checks if any of the products in the order were
* part of a Google Ads Automated Discount session.
*
* If so, it sets a custom variable 'gad' to 'yes'.
* Otherwise, 'gad' remains 'no'.
*
* This can be useful for tracking and analytics purposes
* in Google Ads campaigns.
*
* @param array $custom_variables Existing array of custom variables for the order.
* @param WC_Order $order The WooCommerce order object.
* @return array Modified array of custom variables with 'gad' key added or updated.
*/
add_filter('pmw_google_ads_order_custom_variables', function ( $custom_variables, $order ) {
$custom_variables['gad'] = 'no';
foreach ($order->get_items() as $item_id => $item) {
$product = $item->get_product();
$product_id = $product->get_id();
if (function_exists('sgadwc_is_product_in_discount_session')) {
if (sgadwc_is_product_in_discount_session($product_id)) {
$custom_variables['gad'] = 'yes';
break;
}
// do something
}
}
return $custom_variables;
}, 10, 2);