DuracellTomi's Google Tag Manager for WordPress

Popis

Google Tag Manager (GTM) is Google’s free tool for everyone to manage and deploy analytics and marketing tags as well as other code snippets
using an intuitive web UI. To learn more about this tool, visit the official website.

This plugin places the GTM container code snippets onto your wordpress website so that you do not need to add this manually.
Multiple containers are also supported!

The plugin complements your GTM setup by pushing page meta data and user information into the so called data layer.
Google’s official help pages includes more details about the data layer.

Some parts of the plugin require PHP 5.6 newer.
PHP 7.0 or newer is recommended.

Please note that PHP 5.6 is nearing its end of life cycle thus it is recommended to upgrade. If you are not sure which version you are using, please contact
your hosting provider for support.

GTM container code placement

The original GTM container code is divided into two parts: The first part is a javascript code snippet that is added to the <head>
section of every page of the website. This part is critical to enable all features of GTM, and this plugin helps to place this part
correctly on your site. The second part is an iframe snippet that acts as a failsafe/fallback should users‘ JavaScript be disabled.
Google recommends – for best performance – to place this code snippet directly after the opening <body> tag on each page.
Albeit not ideal, it will work when placed lower in the code. This plugin provides a code placement option for the second code snippet.
Inherently, WordPress does not offer a straight-forward solution to achieve this, however Yaniv Friedensohn showed me a solution
that works with most themes without modification:

I added this solution to the plugin, currently as an experimental option.

Sites using the Genesis Framework should choose the „Custom“ placement option. No theme modification is needed for this theme
however, the Google Tag Manager container code will be added automatically.

logged in user email address (to comply with GTM terms of service do not pass this on to Google tags)

site search data

site name and id (for WordPress multisite instances)

Browser / OS / Device data

(beta)

browser data (name, version, engine)

OS data (name, version)

device data (type, manufacturer, model)

Data is provided using the WhichBrowser library: http://whichbrowser.net/

Weather data

(beta)

Push data about users‘ current weather conditions into the dataLayer. This can be used to generate weather-related
audience/remarketing lists on ad platforms and allows for user segmentation in your web analytics solutions:

An (free) API key from OpenWeatherMap is required for this feature to work.

ipstack.com is used to determine the site visitor’s location. A (free) API key from IPStack.com is required for this feature to work:
https://ipstack.com/product

Media player events

(experimental)

Track users‘ interaction with any embedded media:

YouTube

Vimeo

Soundcloud

DataLayer events can be chosen to fire upon media player load, media is being played, paused/stopped and optionally when
the user reaches 10, 20, 30, …, 90, 100% of the media duration.

Tracking is supported for embedded media using the built-in oEmbed feature of WordPress as well as most other media plugins
and copy/pasted codes. Players injected into the website after page load are not currently supported.

Scroll tracking

Fire tags based on how the visitor scrolls from the top to the bottom of a page.
An example would be to separate „readers“ (who spend a specified amount of time on a page) from „scrollers“
(who only scroll through within seconds). You can use these events to fire Analytics tags and/or remarketing/conversion tags
(for micro conversions).

Scroll tracking is based on the solution originally created by

Nick Mihailovski

Thomas Baekdal

Avinash Kaushik

Joost de Valk

Eivind Savio

Justin Cutroni

Original script:
http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/

Google AdWords remarketing

Google Tag Manager for WordPress can add each dataLayer variable as an AdWords remarketing custom parameter list.
This enables you to build sophisticated remarketing lists.

Blacklist & Whitelist Tag Manager tags and variables

To increase website security, you have the option to white- and blacklist tags/variables.
You can prevent specific tags from firing or the use of certain variable types regardless of your GTM setup.

If the Google account associated with your GTM account is being hacked, an attacker could easily
execute malware on your website without accessing its code on your hosting server. By blacklisting custom HTML tags
and/or custom JavaScript variables you can secure the Tag Manager container.

Integrácia

Google Tag Manager for WordPress integrates with several popular plugins. More integration to come!

Časté otázky

Tutorials for various Google Tag Manager settings and implementation are available on my website:
https://gtm4wp.com/how-to-articles/

PayPal / 3rd party payment gateway transactions in WooCommerce are not being tracked in Google Analytics

PayPal and some other 3rd party payment gateways do not redirect users back to your website upon successful transaction by default.
It offers the route back for your customer but it can happen that users close the browser before arriving at your thankyou page
(aka. order received page). This means that neither Google Analytics tags or any other tags have the chance to fire.

Enable auto-return in your payment gateway settings. This will instruct them to show a quick info page after payment
and redirect the user back to your site. This will improve the accuracy and frequency of tracked transactions.

Why isn’t there an option to blacklist tag/variable classes

Although Google recommends to blacklist tags and variables using classes, people struggle to know
which tags/variables gets affected. Therefore I opted for individual tags and variables rather than classes
on the blacklist tabs.

Regarding variables; ensure they are not part of any critical tags as blacklisting such variables will render said tags useless.

gtm4wp.reading.startReading: the visitor started to scroll. The timeToScroll dataLayer variable stores duration since the article loaded (in seconds)

gtm4wp.reading.contentBottom: the visitor reached the end of the content (not the page!). timeToScroll dataLayer variable updated

gtm4wp.reading.pagebottom: the visitor reached the end of the page. timeToScroll dataLayer variable updated

gtm4wp.reading.readerType: based on time spent since article loaded we determine whether the user is a ‚scanner‘ or ‚reader‘ and store this in the readerType dataLayer variable

Example use cases: using these events as triggers, you can fire Google Universal Analytics and/or AdWords remarketing/conversion tags
to report micro conversions and/or to serve ads only to visitors who spend more time reading your content.

Can I exclude certain user roles from being tracked?

This is easily managed through GTM itself. If you want to exclude logged in users or users with certain user roles,
use the corresponding dataLayer variable (visitorType) and an exclude filter in Google Tag Manager.

How do I put the Google Tag Manager container code next to the opening body tag?

By default the plugin places the iframe tag in the footer of the page. To change it, go to the plugin’s admin section
and select „Custom“ from the placement settings. Unless you use the Genesis Framework theme, you will also need to
edit your template files.

Go to wp-content/plugins/themes/<your theme dir> and edit header.php.
In most cases you will find the opening <body> tag here. If you can not find it, contact the author of the theme and
ask for instructions.

Create a new line right below the body tag and insert this line of code:

Be careful not to place this line within any <div>, <p>, <header>, <article> tags.
It may break your theme.

There is also an option named „Codeless“ which attempts to place the container code correctly
without additional theme tweaks. It may or may not work, this is an experimental feature, use it accordingly.

Currently WordPress has two ‚commands‘ or ‚hooks‘ that a programmer can use: one for the <head> section and
one for the bottom of <body>. There is no way to inject any content after the opening <body> tag without manually
editing your template files. Fortunately some theme authors already resolved this so in some cases you do not need
to edit your template.

I suggest that try the Custom placement (easiest) and use Google Tag Assistant Chrome browser extension to check
whether the container code is placed as expected. If it shows an error, go ahead and edit your theme manually.

Facebook like/share/send button events do not fire for me, why?

It is a Facebook limitation. Click event tracking is only available for html5/xfbml buttons.
If you or your social plugin inserts the Facebook buttons using IFRAMEs (like Sociable), it is not possible to track likes.

Updated: moved most of the inline JavaScript codes into separate .js files which should help cache plugins to do their job much better when my plugin is active

Fixed: wrong ecomm_pagetype on product search result pages

Fixed: PHP notice in some cases when geo data was not loaded properly

Fixed / Added: freegeoip.net was rebranded to ipstack.com and an API key is needed now even for free usage. You can now add your API key so that weather data and geo data can be added into the data layer

Warning: some plugin features will be remove from v1.10, most of them can be tracked now using pure Google Tag Manager triggers:

Social actions

Outbound link click events

Download click events

Email click events

Warning: PHP 5.6 is now the minimum recommended version to use this plugin. I advise to move to PHP 7.x

1.8.1

Added: new visitorIP data layer variable to support post-GDPR implementations where for example internal traffic exclusion has to be made inside the browser

Fixed: JavaScript error around the variable gtm4wp_use_sku_instead

Fixed: added _ as a valid character for gtm_auth GTM environment variable

Fixed: corrected typo – gtm4wp.checkoutStepEEC

Fixed: two strings were not recognized by WordPress Translate on the admin page

Fixed: some other plugins call found_variation event of WooCommerce without product variation data being included

Fixed: product name included variation name on order received page which broke GA product reports

Fixed: in some cases, no contact form 7 data was being passed to the gtm4wp.contactForm7Submitted event

1.5.1

Fixed: clicks on products in product list pages redirected to undefined URLs with some themes.

1.5

Lots of WooCommerce ecommerce codes has been changed and extended, please double check your measurement after upgrading to this version!

Added: warning message if you are using PHP 5.3 or older. Browser/OS/Device tracking needs 5.4 or newer

Added: Email address of the logged in user into the visitorEmail dataLayer variable. Remember: to comply with GTM TOS you are not allowed to pass this data towards any Google tag but you can use this in any other 3rd party tag.

Added: gtm4wp_eec_product_array WordPress filter so that plugin and theme authors can add their own data for enhanced ecommere product arrays

Fixed: JavaScript error in WooCommerce stores when enhanced ecommerce enabled and a product being clicked in a widget area

Fixed: Order data not present in some cases on the order received page

Changed: Extended „User SKUs instead of IDs for remarketing“ option to be also applied to ecommerce product data arrays

Changed: Use wc_clean instead of the deprecated function woocommerce_clean

Changed: New, divided GTM container implemented – a fixed part in the and an iframe part placed using the container placement option you’ve set earlier

1.0

The plugin itself is now declared as stable. This means that it should work with most WordPress instances.
From now on each version will include features labeled as:

Beta: the feature has been proven to work for several users but it can still have some bugs

Experimental: new feature that needs proper testing with more users

Deprecated: this feature will be removed in a future version

If you see any issue with beta or experimental functions just disable the checkbox. Using this error messages should disappear.
Please report all bugs found in my plugin using the contact form on my website.

0.8.1

0.8

Updated: Added subtabs to the admin UI to make room for new features 🙂

Updated: WhichBrowser library to the latest version

Added: You can now dismiss plugin notices permanently for each user

Added: weather data. See updated plugin description for details

Added: Enhanced E-commerce for WooCommerce (experimental!)

Fixed: PHP notice in frontend.php script. Credit to Daniel Sousa

0.7.1

Fixed: WooCommerce 2.1.x compatibility

0.7

Updated/Fixed: dataLayer variables are now populated at the end of the head section. Using this the container code can appear just after the opening body tag, thus Webmaster Tools verification using Tag Manager option will work

Updated: click events are now disabled by default to reflect recently released Tag Manager auto events. I do not plan to remove this functionality. You can decide which solution you would like to use 🙂

Updated: language template (pot) file and Hungarian translation

Added: new form move events to track how visitors interact with your (comment, contact, etc.) forms

Added: event names to admin options page so that you know what events to use in Google Tag Manager