Metronet Tag Manager (original) (raw)

Integrate Google Tag Manager into your website.

The great thing about Google Tag Manager (GTM) is that you are able to gather most of your tracking scripts in one place. You can then fire these scripts whenever you want, specified by the rules you set up. This sounds great, right? Well, it is. The only problem is that sometimes it takes some time to set these rules up. This implementation can either set a dataLayer variable in the dataLayer before the tag manager script is loaded or push an HTML event handler with the variable “event” to the dataLayer when a button is clicked. The problem is that this isn’t always that easy to do when you don’t have the ability/access to add the code to your site.

This is where the Metronet Tag Manager plugin shines. It unlocks the power of the dataLayer so you can easily set macros and firing rules on almost any element.

This plugin lets you:

Please note that for this plugin to work, a slight customization is needed. WordPress doesn’t let you load scripts straight after the opening tag, where the GTM script needs to be placed to work correctly. To fix this, you need to add <?php do_action( 'body_open' ); ?> just after the <body> tag, and that’s it.

Note, If you are using WordPress 5.2. and up, contact your theme developer and ask them to insert <?php wp_body_open(); ?> just after the opening body tag of their theme. Here is some code to show the theme developer to make it compatible with Metronet Tag Manager.

Please let us know if you have any feature requests or issues with this plugin.

Below are a couple of resources you might find valuable if you are new to Google Tag Manager

Official Google Tag Manager website
https://developers.google.com/tag-manager/

Tracking Google Analytics Events with Google Tag Manager
https://wpmetronet.com/how-to-track-pdf-downloads-with-tag-manager-on-wordpress/

Make Analytics Better with Tag Management and a Data Layer
https://wpmetronet.com/the-benefits-of-using-a-tag-manager-plugin-on-wordpress/

Filtering Variables

If you choose to place variable values inside percentage signs (e.g., %replace_test%), you can filter these as necessary.

Here’s an example:

add_filter( 'gtm_replace_test', 'gtm_replace_test', 10, 3 );
function gtm_replace_test( <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi><mi>o</mi><mi>t</mi><mi>a</mi><msub><mi>l</mi><mi>m</mi></msub><mi>a</mi><mi>t</mi><mi>c</mi><mi>h</mi><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">total_match, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0197em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">m</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">c</span><span class="mord mathnormal">h</span><span class="mpunct">,</span></span></span></span>match, $post_id ) {
    return "replaced with content";
}

The filter name is gtm_ with the suffix of replace_test, since that content is inbetween the percentage signs.

This plugin provides 1 block.

  1. Just unzip and upload the “metronet-tag-manager” folder to your ‘/wp-content/plugins/’ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Modify your theme’s header.php to include <?php do_action( 'body_open' ); ?> right after the opening <body> tag.
  4. Go to the plugin’s settings and input your Google Tag Manager data.

Note: if you are using WordPress 5.2. and up, contact your theme developer and ask them to insert <?php wp_body_open(); ?> just after the opening body tag of their theme. Here is some code to show the theme developer to make it compatible with Metronet Tag Manager.

For custom values, please see the filters section on GitHub.

What is Google Tag Manager

Please refer to the Google Tag Manager FAQ.

What are dataLayer variables?

Please refer to the Google Tag Manager API reference.

What are dataLayer variables used for?

The data layer is an object that contains the information that you want to pass to Google Tag Manager. By setting up rules in Google Tag Manager, these variables can then be used to include the correct snippets or scripts – for example, when a certain button is clicked.

Can I have dynamic values?

Yes. For custom values, please see the filters section on GitHub.

My go to when getting Google Tag Manager set up on a clients site. Very simple and have had no problems setting it up on any of my wordpress sites. I prefer this plugin over similar plugins due to its simplicity and has been more secure than others. While it is simple, don’t assume it can’t handle the bigger projects. It allows the more robust tracking methods and practices some clients need that other plugins simply don’t offer. Just be sure to follow the installation instructions and you will be good to go!

The plugin is helpful with installing Google Tag Manager. Works on WordPress multisite websites. The plugin is simple, straightforward, and more secure than a simple “insert headers or footers” plugin.

I could not verifie the search console via tag manager using this plugin. It places the code in the wrong place. Maybe i did something wrong, but it’s something you should look in to.

Simple, unobtrusive – great plugin. And whenver i see the name i always think “If young metro don’t trust you?”

I offer Google Analytics training and students always struggle with adding dataLayer variables. Your plugin really simplifies the process – Thank You!

Turn on support for translation into other languages. Did the translation into Russian, could not to apply)

Read all 8 reviews

“Metronet Tag Manager” is open source software. The following people have contributed to this plugin.

Contributors

1.5.5

1.5.4

1.5.3

1.5.2

1.5.1

1.5.0

1.3.0

1.2.9

1.2.7

1.2.3

1.2.1

1.2.0

1.1.0

1.0.8

1.0.6

1.0.5

1.0.4

1.0.3

1.0.2

1.0.1

1.0