Woocommerce Google Adwords Conversion Tracking Tag Shortcodes

Below, you’ll find a detailed guide on how to add the Woocommerce Google Adwords Conversion Tracking Tag Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Woocommerce Google Adwords Conversion Tracking Tag Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Woocommerce Google Adwords Conversion Tracking Tag Plugin and the shortcodes it provides:

Plugin Icon
Pixel Manager for WooCommerce – Track Google Analytics, Google Ads, TikTok and more

"Pixel Manager for WooCommerce is a versatile plugin enabling tracking of Google Analytics, Google Ads, TikTok, and more. Its slug is 'woocommerce-google-adwords-conversion-tracking-tag'."

★★★★☆ (300) Active Installs: 50000+ Tested with: 6.3.2 PHP Version: 7.3
Included Shortcodes:
  • [view-item]
  • [conversion-pixel]

[view-item] Shortcode

The WooCommerce-Google-Adwords-Conversion-Tracking-Tag plugin shortcode ‘view-item’ is used to display specific product details. This shortcode fetches product data based on the ‘product-id’ attribute. It then prints the product data layer script and triggers a ‘wpmViewItem’ event. This event is used to track product views in Google Adwords.

Shortcode: [view-item]

Parameters

Here is a list of all possible view-item shortcode parameters and attributes:

  • product-id – Identifier used to fetch specific product details

Examples and Usage

Basic example – Utilizing the shortcode to display a specific product by referencing its product ID.

[view-item product-id=123 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [view-item] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('view-item', [ __CLASS__, 'view_item' ]);

Shortcode PHP function:

function view_item( $attributes ) {

		self::init();

		$shortcode_attributes = shortcode_atts(
			[ 'product-id' => null ],
			$attributes
		);

		if ($shortcode_attributes['product-id']) {

			$product = wc_get_product($shortcode_attributes['product-id']);

			if (Product::is_not_wc_product($product)) {
				wc_get_logger()->debug('get_product_data_layer_script received an invalid product', [ 'source' => 'PMW' ]);
				return;
			}

			Product::print_product_data_layer_script($product, false, false);

			?>

			<script>
				jQuery(window).on("wpmLoad", function () {
					jQuery(document).trigger("wpmViewItem", wpm.getProductDetailsFormattedForEvent(<?php esc_html_e($shortcode_attributes['product-id']); ?>))
				})
			</script>
			<?php
		}
	}

Code file location:

woocommerce-google-adwords-conversion-tracking-tag/woocommerce-google-adwords-conversion-tracking-tag/classes/pixels/class-shortcodes.php

[conversion-pixel] Shortcode

The WooCommerce-Google-Adwords-Conversion-Tracking-Tag plugin shortcode, ‘conversion-pixel’, is used to initialize tracking scripts. It sets default values for various tracking events and allows for customization via attributes. If the ‘fbq-event’ attribute is set, it overwrites the ‘meta-event’ attribute, ensuring backward compatibility.

Shortcode: [conversion-pixel]

Parameters

Here is a list of all possible conversion-pixel shortcode parameters and attributes:

  • pixel – Chooses which pixel to use for tracking.
  • gads-conversion-id – Google Ads conversion ID for tracking.
  • gads-conversion-label – Label for Google Ads conversion tracking.
  • lintrk-event – Event name for LinkedIn tracking.
  • meta-event – Event name for Meta (Facebook) tracking.
  • twc-event – Event name for Twitter conversion tracking.
  • pinc-event – Event name for Pinterest tracking.
  • pinc-lead-type – Type of lead for Pinterest tracking.
  • ms-ads-event – Event name for Microsoft Ads tracking.
  • ms-ads-event-category – Category of Microsoft Ads event.
  • ms-ads-event-label – Label for Microsoft Ads event.
  • ms-ads-event-value – Value of Microsoft Ads event.
  • outbrain-event – Event name for Outbrain tracking.
  • reddit-event – Event name for Reddit tracking.
  • snap-event – Event name for Snapchat tracking.
  • taboola-event – Event name for Taboola tracking.
  • tiktok-event – Event name for TikTok tracking.

Examples and Usage

Basic example – A simple usage of the shortcode to track conversions, using the default parameters.

[conversion-pixel /]

Advanced examples

Customizing the shortcode to track a specific event, such as a user completing a registration form. This is done by changing the ‘twc-event’ parameter to ‘CompleteRegistration’.

[conversion-pixel twc-event='CompleteRegistration' /]

Further customization of the shortcode to track a lead event on Pinterest, by setting the ‘pinc-event’ parameter to ‘lead’ and specifying the ‘pinc-lead-type’.

[conversion-pixel pinc-event='lead' pinc-lead-type='signup' /]

Using the shortcode to track an event on Microsoft Ads, by setting the ‘ms-ads-event’ parameter to ‘submit’, the ‘ms-ads-event-category’ to ‘form’, and the ‘ms-ads-event-label’ to ‘lead’.

[conversion-pixel ms-ads-event='submit' ms-ads-event-category='form' ms-ads-event-label='lead' /]

PHP Function Code

In case you have difficulties debugging what causing issues with [conversion-pixel] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('conversion-pixel', [ __CLASS__, 'conversion_pixel' ]);

Shortcode PHP function:

function conversion_pixel( $attributes ) {

		self::init();

		self::function_exists_script();

		$pairs = [
			'pixel'                 => 'all',
			'gads-conversion-id'    => Options::get_google_ads_conversion_id(),
			'gads-conversion-label' => '',
			'lintrk-event'          => null,
			'meta-event'            => 'Lead',
			'twc-event'             => 'CompleteRegistration',
			'pinc-event'            => 'lead',
			'pinc-lead-type'        => '',
			'ms-ads-event'          => 'submit',
			'ms-ads-event-category' => '',
			'ms-ads-event-label'    => 'lead',
			'ms-ads-event-value'    => 0,
			'outbrain-event'        => '',
			'reddit-event'          => 'Lead',
			'snap-event'            => 'SIGN_UP',
			'taboola-event'         => '',
			'tiktok-event'          => 'SubmitForm',
		];

		$shortcode_attributes = shortcode_atts($pairs, $attributes);

		// If $attributes['fbq-event'] is set, overwrite $attributes['meta-event'] with $attributes['fbq-event']
		// This is to maintain backwards compatibility with the old shortcode
		if (isset($attributes['fbq-event'])) {
			$shortcode_attributes['meta-event'] = $attributes['fbq-event'];
		}

		self::output_tracking_scripts($shortcode_attributes);
	}

Code file location:

woocommerce-google-adwords-conversion-tracking-tag/woocommerce-google-adwords-conversion-tracking-tag/classes/pixels/class-shortcodes.php

Conclusion

Now that you’ve learned how to embed the Woocommerce Google Adwords Conversion Tracking Tag Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *