Skip to main content

Filters

While our goal is to make the plugin very simple to use through the user interface, this can be limiting for users and developers who need much more granular control over the plugin's output. For those users we provide filters which give them the option to adjust the plugin's behavior programmatically, making the options almost limitless.

Filters can be added to the functions.php file in your child-theme or by using them in a custom plugin. The easiest and safest way is using them in the functions.php file: functions.php

If you think there is a good use case for a new filter, let us know by sending a feature request here.

Conversion Value Filter

Use the conversion value filter in order to recalculate the conversion value. The output will only affect the conversion value of the paid ads pixels. The Google Analytics conversion value output will not be touched.

add_filter( 'wpm_conversion_value_filter', 'filter_conversion_value', 10, 2 );

Example:

/wp-content/themes/child-theme/functions.php
add_filter('wpm_conversion_value_filter', function ($order_total, $order) {
/**
* The order total is the value that is being output as configured
* within the plugin. If you wish to override this and calculate
* the value from scratch, the filter also provides the order object
* with the raw order values.
*
* Example: The average cost to prepare an order for shipping is
* 10% of the order value. Therefore we remove 10% of the order value on
* each order.
**/

return $order_total * 0.9;
}, 10, 2);

Additional Google Ads Conversion Pixels

With the following filter we provide a way ot add more than one Google Ads conversion pixel programmatically.

/wp-content/themes/child-theme/functions.php
/*
* Since version 1.8.2 of the plugin.
*
* This filter will add aditional conversion ID and label pairs to the output
* of the Google Ads pixel.
*
* It will add the output to every page with the Google Ads remarketing pixel,
* including the purchase confirmation page.
*
* Place the following code into your functions.php and replace the placeholders.
*
* It will only work if the main conversion ID and conversion label are set
* within the plugin (which activates the Google Ads conversion tracking in
* the first place).
*/


add_filter('wpm_google_ads_conversion_identifiers', function ($conversion_identifiers) {

$conversion_identifiers['CONVERSION_ID_2'] = 'CONVERSION_LABEL_2';
$conversion_identifiers['CONVERSION_ID_3'] = 'CONVERSION_LABEL_3';
return $conversion_identifiers;
});

Adjust Google Analytics Config Parameters

To keep the user interface lightweight we only included basic parameters like Enhanced Link Attribution. For those who need much more granular control over the Google Analytics config parameters we provide a filter. The filter can also be used to override parameters from the user interface.

info

GA4 processes IPs from pageviews anonymized by design. This can't be changed. IP Anonymization in Google Analytics For Universal Analytics we've set the default parameters to also anonymize IPs. That setting can be overwritten with the filter below.

The following code will remove the anonymize_ip parameter on all Google Universal Analytics configs:

/wp-content/themes/child-theme/functions.php
add_filter('wpm_ga_ua_parameters', function ($analytics_parameters, $analytics_id) {

unset($analytics_parameters['anonymize_ip']);
return $analytics_parameters;
}, 10,2);

The following code will adjust the parameters only for the given Google Universal Analytics property:

/wp-content/themes/child-theme/functions.php
add_filter('wpm_ga_ua_parameters', function ($analytics_parameters, $analytics_id) {

if('UA-12345678-3' == $analytics_id){

unset($analytics_parameters['anonymize_ip']);

/**
* The following parameter setting will override the one set
* in the user interface.
**/
$analytics_parameters['link_attribution'] = true;
}

return $analytics_parameters;
}, 10,2);

Or maybe, you want to set much more specific settings for link_attribution in your Google Universal Analytics property, like specified here:

/wp-content/themes/child-theme/functions.php
add_filter('wpm_ga_ua_parameters', function ($analytics_parameters, $analytics_id) {

if('UA-12345678-3' == $analytics_id){

$analytics_parameters['link_attribution'] = [
'cookie_name' => '_gaela',
'cookie_expires' => 60,
'levels' => 2
];
}

return $analytics_parameters;
}, 10,2);

And with the following filter you can enable the debug mode in GA4.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_ga_4_parameters', function ($analytics_parameters, $analytics_id) {

$analytics_parameters['debug_mode'] = true;

return $analytics_parameters;
}, 10,2);

Product ID Output Filter for Paid Ads Pixels

To keep the UX simple and the setup consistent over several advertising channels, there is only one setting in the UX to adjust the product ID output. The same ID then will be used for all paid ads pixels. The standard setting is either the post ID (eg. 14), the ID for the WooCommerce Google Feed plugin (eg. woocommerce_gpf_14) or the SKU (eg. Hoodie). In some cases you might need to use a different ID type on different channels. Maybe you're using the post ID for Google Ads, and the SKU for Meta (Facebook). In this case the following filter will adjust the output for a specific pixel. It is even possible to completely customize the ID, if necessary.

info

We strongly recommend to use the post ID for all product catalogs and for the product ID output. It is the most compatible way and causes the least troubles.

By adding the pixel name to the filter name, you can chose which pixel you want to adjust. For Meta (Facebook) use wpm_product_id_type_for_facebook, for Microsoft Ads (Bing) use wpm_product_id_type_for_bing, etc. Depending on which version of the plugin you have, you can use the following pixel filters: google_ads, facebook, bing, twitter, pinterest, snapchat, tiktok

The default values are post_id for the post ID, gpf for the WooCommerce Google Feed ID output (eg. woocommerce_gpf_14) and sku for the SKU.

Here's an example on how to switch the product ID output for Meta (Facebook) to the SKU:

/wp-content/themes/child-theme/functions.php
add_filter('wpm_product_id_type_for_facebook', function () {
return 'sku';
});

Here's an example to switch the Meta (Facebook) output to post ID:

/wp-content/themes/child-theme/functions.php
add_filter('wpm_product_id_type_for_facebook', function () {
return 'post_id';
});

You have even the option to completely customize the product ID output and assign it to a specific channel with the wpm_product_ids filter.

In the following example use the wpm_product_ids filter to add one or more custom IDs for each product. In a second step, use the wpm_product_id_type_for_ filter to assign the new custom ID to one or more specific pixels.

The following filter creates the custom product IDs.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_product_ids', function ($product_ids, $product) {
$product_ids['custom1'] = 'custom_type_' . $product->get_id();
$product_ids['custom2'] = 'custom_pinterest_catalog_' . $product->get_sku();

return $product_ids;
}, 10, 2);

Then assign the new custom product IDs to the channels of your choice.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_product_id_type_for_google_ads', function () {
return 'custom1';
});
/wp-content/themes/child-theme/functions.php
add_filter('wpm_product_id_type_for_pinterest', function () {
return 'custom2';
});

Google Analytics Product ID Output Filter

By default the plugin uses the post ID as identifier for Google Analytics. This filter allows you to change this to the SKU.

info

The main reasons why the plugin uses the post ID by default are:

  1. The post ID is more reliable. A shop owner might not add SKUs to all products, leaving the field sometimes empty. But we need to send an identifier to Google Analytics. (In the case the shop owner doesn't add a SKU to a product, we will fall back to the post ID.)
  2. The products can be identified by the product name in Google Analytics anyway.
  3. It is easier to search for a product ID in WooCommerce or in Google Analytics, so it's also more practical to use the post ID.
/wp-content/themes/child-theme/functions.php
add_filter('wpm_product_id_type_for_google_analytics', function () {
return 'sku';
});

View Item List Trigger Filter

The plugin uses a smart trigger for the view_item_list event. It only triggers if a product is actually visible in the viewport for more than 1 second. If a visitor scrolls up and down and sees a product several times, view_item_list will be triggered each time (again, only if visible for more than one second). The following filter allows to tweak that behavior.

Lazy loading products is supported too 😀 (from version 1.9.4)

info

This will only work on a website where caching is off, or after flushing the cache each time you change the settings.

Following settings are available:

  • testMode: It activates the test mode, which will show you a transparent overlay on each product for which view_item_list has been triggered.
  • bacgroundColor: You can change the background color of the test overlay in case you use product images where the overlay would not be visible. This is only relevant for the test mode.
  • opacity: By default the overlay is half transparent. You can adjust the opacity to a level that suits you more. This is only relevant for the test mode.
  • repeat: By default the plugin resends view_item_list events when a visitor scrolls up and down and sees a product multiple times. You can turn this off by setting the value to false. Then the plugin will send only one view_item_list event when a product becomes visible on a page.
  • threshold: This sets how much of a product card must be visible before the event is triggered. With a setting of 1the event triggers only when 100% of the product is visible. The default is 0.8.
  • timeout: This value tells the plugin how long a product must be visible before the view_item_list event is sent. The timer will be reset each time the product leaves the viewport. The time must be set in milliseconds, and the default value is 1000 milliseconds (1 second).
/wp-content/themes/child-theme/functions.php
add_filter('wpm_view_item_list_trigger_settings', function ($settings) {

$settings['testMode'] = true;
$settings['backgroundColor'] = 'green';
// $settings['backgroundColor'] = 'rgba(60,179,113)';
$settings['opacity'] = 0.5;
$settings['repeat'] = true;
$settings['threshold'] = 1;
$settings['timeout'] = 1000;

return $settings;
});

Another simple way to enable the view_item_list demo mode is by appending the parameter vildemomode to the URL you want to test. Don't forget the ?. Example: https://example.com/shop/?vildemomode. This method even works on websites with caching turned on. It will use the default settings.

view_item_list event test mode

view_item_list event test mode 2

Cross Domain Linker Settings for Google

From version 1.10.4 of the premium plugin.

Googles domain linker functionality enables two or more related sites on separate domains to be measured as one. You'll find more information about this functionality here and here.

The domain linker values need to be passed as an array to the filter. The plugin will then output all values as a JavaScript formatted domain linker script.

You'll find a list of all possible parameters over here.

Basic example with multiple domains: You can list multiple string values in the domains property. When the domains property has at least one value, gtag.js will accept incoming domain links by default. This allows you to use the same code snippet on every domain.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_google_cross_domain_linker_settings', function (){

return [
"domains" => [
'example.com',
'example-b.com',
]
];
});

Example output:

gtag('set', 'linker', {
'domains': ['example.com', 'example-b.com']
});

decorate_forms: If you have forms on your site that point to the destination domain, set the decorate_forms property to true.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_google_cross_domain_linker_settings', function (){

return [
"domains" => [
'example.com',
'example-b.com',
],
"decorate_forms" => true,
];
});

url_position: To configure the linker parameter to appear in the URL after a fragment (#) instead of as a query parameter (?) (e.g. https://example.com#_gl=1~abcde5~), set the url_position parameter to fragment.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_google_cross_domain_linker_settings', function (){

return [
"domains" => [
'example.com',
'example-b.com',
],
"decorate_forms" => true,
"url_position" => 'fragment',
];
});

accept_incoming: Once a user arrives at a page on the destination domain with a linker parameter in the URL, gtag.js needs to be configured to parse that parameter.

If the destination domain has been configured to automatically link domains, it will accept linker parameters by default. No additional code is required on the destination domain.

If the destination domain is not configured to automatically link domains, you can instruct the destination page to look for linker parameters. Set the accept_incoming property to true.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_google_cross_domain_linker_settings', function (){

return [
"accept_incoming" => true
];
});

Custom Brand Taxonomy

From version 1.10.9 of the plugin.

If you are using your own product attribute to store brand names for products, you can use this filter to output the brand names for the pixels. The filter must return the taxonomy name for the brand attribute. Usually it is the attribute slug, prefixed with pa_. In this example it would be pa_custom-brand. Depending on how the taxonomy has been created, it also can only be the slug custom-brand. If one doesn't work make sure to try the other.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_custom_brand_taxonomy', function (){

return 'pa_custom-brand';
});

Add custom order confirmation statuses to process

From version 1.16.2

If you use a plugin to add custom order statuses, there is chance that purchase events won't be sent to Google Analytics (if you are using the pro version of the Pixel Manager for WooCommerce). In that case use the following filter to add the new, custom order statuses that mark a paid order.

The reason why this only happens in the pro version of the Pixel Manager for WooCommerce is because the pro version uses the Google Measurement Protocol to transmit purchase events to Google. The advantage of the Measurement Protocol is that it is much more accurate than the browser pixel. But if custom order statuses are added it can happen that some purchase events won't be tracked properly. The below filter helps you to fix this.

/wp-content/themes/child-theme/functions.php
add_filter('wpm_register_custom_order_confirmation_statuses', function ( $statuses ) {

$statuses[] = 'confirm'; // Adds a new custom status called 'confirm'

return $statuses;
});