Hey there, I'm Benjamin from Loves Data. In this video, you will learn how to use the Google Tag
Manager data layer to send additional information to your Google Analytics reports using. This is a
question from one of my YouTube subscribers, Fabio, who wants to know how to report on
users who are logged in on Wordpress. So let's head to Wordpress and take a look...
Okay, let's start by installing the Google Tag Manager for WordPress plugin.
If you've already done this, then you can skip ahead using the links in the description below
this video. To install the plugin, let's select 'Plugins'... And then 'Add New'...
Now let's search for 'Google Tag Manager'...
And let's install the 'Google Tag Manager for Wordpress' plugin...
Let's activate the plugin... Now let's select 'Settings'... And then 'Google Tag Manager'...
We need to start by adding our Google Tag Manager container ID, so let's head to Google
Tag Manager... I've already logged in and opened my Google Tag Manager container, so I can see the
container ID at the top of the window... Let's click this... And then copy the container ID,
it will start with 'GTM' and then a dash... Now let's head back to Wordpress...
And let's past our container ID into the plugin... And click 'Save Changes'...
We can select the tabs in the plugin to view the different configuration options. Let's select
'Basic Data'... This tab includes a number of elements we can enable in the Data Layer.
We can see there are some options enabled by default... Including 'Post type'... 'Category'...
'Tags'... And 'Author name'... This will mean that details about each post on our WordPress site will
be available in the data layer and we can use this to send information to Google Analytics
and any other tags we're using in Google Tag Manager. Take some time to review the
options and decide if you want to enable any additional options, or disable any options.
I'm going to leave these defaults and I'm going to select 'Visitors' at the top...
This lets us include details about our WordPress users in the data layer. I'm going to enable the
option for 'Logged in status'... This will let us see if people are logged into WordPress.
Let's click 'Save Changes'... And now let's view the site... Let's navigate to the blog post...
We can see at the bottom of the post the name of the author... And the category used
for the post... Okay, now let's right click on the page... And select 'View Source'...
If we scroll down the source code for the page...
We can see the data layer that is being created and populated by the plugin...
If you're new to Google Tag Manager, or haven't seen a data layer before, it lets
you expose information that can then be used by our variables, tags, and triggers in Google Tag
Manager. For our Wordpress site, the plugin we are using is creating the data layer and populating it
with different details about our site. If you'd like to learn more about the data layer, then
check out the extra resources in the description below this video. Okay, so we can see the data
layer includes different variables, along with a value for each variable. We can see 'visitor
login state' is set to 'logged in' because I'm currently logged in to Wordpress. We can see
'page post type'... The 'page category' for the post... And even the 'page post author'... We
can use these variables and their values in Google Tag Manager. Let's head to Google Tag Manager...
And let's select 'Variables'...
To use the information from the data layer we need to configure a variable for each value
we want to use. So let's click 'New' next to 'User-Defined Variables'...
Let's name the variable. You can name it anything you want, but I'm going to name my variable
'WordPress Login State', so I know it's information from WordPress and its details
about whether someone is logged in or not... Now we select 'Variable Configuration'...
And we need to choose 'Data Layer Variable'... Now we need to enter the name of the variable
from the data layer. So let's enter 'Visitor Login State'... This needs to be entered exactly as we
saw it in the data layer, so if in doubt, you can copy and paste it from your source code...
We can leave the other settings... And let's click 'Save'... While we're here, let's create one more
variable... Let's click 'New'... And let's name the variable 'Wordpress Post Author'...
And let's select configuration... And choose 'Data Layer Variable' again...
Now let's enter 'page post author'... And save the variable...
Now we can use the value of the variables from the data layer in our tags, triggers, and even other
variables. Let's select 'Tags'... Today I'm going to send the details from the data layer to my
Google Analytics 4 property, but you can also use the variable we just created to send information
to Universal Analytics or any other tags you like. Let's select my Google Analytics 4 tag...
This is a configuration tag for Google Analytics 4, and this tag will automatically send a pageview
to my reports. So let's add a field, so that we can send the information from the data layer as
a parameter with the pageview. To do this, let's select 'Fields to Set'... And click 'Add Row'...
I'm going to name my parameter 'wordpress', 'underscore', 'login', but you can name this
anything you like... And now we click the variable icon for the 'Value'...
And we can choose the 'WordPress Login State' variable we just created...
This will mean the value of the parameter will be the value from the data layer.
Let's add another row... And let's enter 'wordpress', 'underscore', 'author' as the name...
And let's select the variable icon for the value...
And let's select the 'Wordpress Post Author' variable... Now let's save the tag...
Now let's preview our changes... We enter our website's URL...
And we can see Tag Assistant has loaded on my demo site...
So let's select the 'Tag Assistant' tab... Let's select the 'Container Loaded' event on the left...
And now let's select our Google Analytics 4 tag... We can see the two parameters we
configured in Google Tag Manager... And if we select 'Values' on the top right corner, we can
even see the values that have been sent to Google Analytics... So we can see the value of 'logged
in' because I'm logged in to Wordpress. And the name of the author of the post we're viewing...
Finally, let's head to Google Analytics... And let's open the 'Debug View'...
We can see the events that have been sent to Google Analytics...
And we can select the pageview event to see the parameters...
Again, we can see the values from the data layer that have been sent using our tag and the variable
we configured in Google Tag Manager. Now to make use of these parameters in Google Analytics 4,
you will need to register them. To do this, let's select 'Custom Definitions'...
And let's create a new custom dimension... Let's name the dimension 'Wordpress Login'...
I'm going to leave the scope as the default... And we can enter a short description...
Then we need to enter the name of the event parameter exactly how it will be sent to Google
Analytics. Since I named mine 'wordpress', 'underscore', 'login' in the Google Analytics
4 tag in Google Tag Manager, this is what I need to enter. If the parameter has already
been collected by Google Analytics, then it will also be available using the drop-down.
Now we can save the custom dimension... Moving forward, you will now be able to see the dimension
in your reports and you can even create your own reports using the dimension in the 'Analysis Hub'.
To learn more about Google Analytics 4, I've included extra resources in the description
below this video. So that's how you can send additional information to Google Analytics
with the help of the Google Tag Manager data layer. If you're not using Wordpress,
then I recommend checking out the support articles for the website platform you're using.
There might be information automatically available in the data layer, or maybe you can use another
plugin to collect additional insights. What information are you collecting with the help
of Google Tag Manager? I'd love to know! Let me know in the comments below. And if you found
this video helpful, please like it, so I know to make more videos like this. See you next time!