Twitter ad conversion tracking WordPress shortcode

The Twitter plugin for WordPress makes it easy to track Twitter advertising campaign conversions or build a remarketing audience with the twitter_tracking WordPress shortcode. Configure a widget, add the shortcode to a post editor, or evaluate the shortcode using the do_shortcode WordPress function to add Twitter ads tracking to your webpages.

The Twitter plugin only includes additional trackers when explicitly specified by your website or its authors. Please read Twitter’s advertising tracker disclosure policies in case you need to modify your site’s privacy policy before using this feature.

Copy a universal website tag from a code snippet generated on ads.twitter.com.

Screenshot universal website tag code snippet

Supported shortcode parameters

Attribute Description Example
id The Twitter advertising tracking identifier generated by Twitter’s conversion tracking tools. 12b34

Set the tracking ID using a filter

A website may set tracking IDs for specific pages by acting on the associative array passed to the shortcode_atts_twitter_tracking filter.

A shortcode parameter with no explicitly provided id attribute will return an empty string unless overridden during the WordPress filter process.

Example:

/**
 * Set a tracking ID for specific pages
 *
 * @param array $out Parsed user-defined valid attributes or default attribute value
 * @param array $pairs supported attributes and their default values
 * @param array $attributes user-defined attributes in the shortcode tag
 *
 * @return array options array with our customization applied
 */
function twitter_tracking_custom_options( $out, $pairs, $attributes )
{
  if ( is_page( 42 ) ) {
    $out['id'] = '12b34';
  }
  return $out;
}
add_filter( 'shortcode_atts_twitter_tracking', 'twitter_tracking_custom_options', 10, 3 );