window.dataLayer = window.dataLayer || ;
- Maintainability - the data layer should not be impacted by front end changes to the site
- Reliability - data can be pushed programmatically from backend systems
- Extensibility - data can be collect even if it is not presented on-screen
Because this data is pushed programmatically, it can present a barrier to entry for non-developers.
The GTM4WP (Google Tag Manager for WordPress) plugin helps WordPress sites push data to the data layer for consumption by Google Analytics, without the need for custom code.
If you run a WordPress site, follow this link to install the plugin: Installing the plugin
In short, you will have to install the plugin via WordPress then input your GTM Container ID in the box below.
Capturing Data Layer Variables
The values we are pushing to the data layer will not be automatically collected by Google Analytics (GA). We must create Data Layer Variables in GTM in order to capture these values and pass them to GA as event parameters or custom dimensions.
Example Data Layer Snippet
Corresponding Data Layer Variable in Google Tag Manager
Say you want to capture the revenue value above so it can be sent with the Transaction/Purchase event Tag. The Data Layer Variable Name below will return this value when it is present in the data layer. In this case the data layer object contains nested dictionaries, which requires dot (".") notation to access.
After creating the data layer variable above, you may include it as an event parameter as demonstrated below. Keep in mind that this variable value will remain undefined until the corresponding data layer value is pushed.
Enabling Ecommerce - WooCommerce, Shopify, Printify
These instructions are only for WordPress WooCommerce, Shopify, and Printify sites.
After installing the WP4GTM plugin, login to as WordPress admin and navigate to the plugin settings:
Plugins > Installed Plugins > Google Tag Manager for WordPress > Settings
From within Settings, choose the tabs shown below: Integration > WooCommerce.
- Check the box next to Track enhanced e-commerce.
- Set the number next to Products per impression.
- Click Save Changes.
Finally, deactivate any ecommerce Transactions Tags you may have already implemented through GTM.
- From GTM4WP plugin settings, navigate to Events > General events.
- From here, you can check the box next to Form fill events in order to gain supplemental data layer support.
- From GTM4WP plugin settings, navigate to Basic data > Weather & geo data
- From here, you can check the box next to Geo data push those details to the data layer.
This is an experimental service which requires an IPStack.com API key.
Under Basic data > Visitors you will find options for data layer support of authenticated/logged in users. Check any that can enhance your tracking implementation. You may choose to capture the values with GTM Data Layer Variables for inclusion with Tags as custom dimensions, event parameter, or label values.
Example of including the data variable as a Page View User Property
Use this feature to push data layer values regarding user scroll activities. This may be useful if you want to analyze how many users view the entire contents of a web page, like articles or blogs.
The GTM4WP plugin can greatly enhance your tracking in terms of accuracy and maintainability. Install the plugin and configure it as needed to enhance your data layer with more information. Then capture those values using data layer variables created through GTM. Finally, include those variable values within your Tags as Event Parameters for analysis in Google Analytics.