Google Analytics for Hotels Advanced via Tag Manager | Tracking Adults & Children on a Search Level

Share this post.


Every single report in Google Analytics is essentially made up by two different elements, dimensions and metrics.

And the difference is that dimensions are the attributes of your data, whilst metrics are the quantitative measurements of those attributes.

And so whether you look into your Source & Medium report, or Events report, or Location report and even Conversion report, on the left the first column is your dimension, meaning your attribute; on the right-hand side, as of the second column onwards, are all the metrics, meaning your performance respectively to that specific dimension.

The vast majority of these dimensions and metrics are automatically tracked, as long as you have Google Analytics installed on your website or booking engine.

Maybe the only exception is about transactions, meaning your reservations, because for that you at least need to map the data from your booking engine to the structure of Google Analytics.

What most hoteliers are not aware of though, is that in Google Analytics we can create as many custom dimensions and as many custom metrics as we want.

And what are custom dimensions and metrics for?

We can literally send everything that we want as long as we know how to do it.

And that’s the purpose of this video.

So in the previous video, we talked about the importance of tracking on a search level how many nights people search for, for how many adults, for how many children people search for and how much in advance, meaning the booking window, or eventually the search window, meaning the time that elapses between the booking date and the arrival date.

In today’s video we’re going to see how to create these custom dimensions and how can we feed them through our booking engine in order to send the right value of number of adults and number of children.

So without further ado, let’s dig in.

Google analytics advanced_course for hotels

Get Notified When GA4 Hotels Advanced Will Be Launched!

No commitment required.

Create a Custom Dimension in Google Analytics

We’re going to go through two different steps; the first one is about creating custom dimensions in Google Analytics, meaning creating the space within your Google Analytics account to store the values that later on we are going to send through the booking engine.

To do so, we go into our admin panel and then in the central column, in the property column, we scroll all the way down until you see custom definitions.

And you see here, we have custom dimensions and custom metrics. For the purpose of this video, we’re going to be tracking adults and children, meaning how many adults and how many children people search for when using our booking engine.

And so we’re going to hit custom dimensions.

Now click New Custom Dimension. And here we start of course by naming our custom dimension, we can give any random name and I’m going to simply call it Adults + Children.

And then what’s important to know is the scope.

Now, we usually have four different scopes: hit, sessions, users and products.

I’m not going to get into each and every one of them, but for the purpose of our goal, meaning tracking adults and children, we’re going to be using Session, and the reason is because we want to track on a session level what is the number of adults and the number of children used in the booking engine.

And so after that we’re just simply going to create the new custom dimension. We’re not going to be using these codes because these are the codes that we could potentially be using when we are not working with Google Tag Manager.

But consider it then we are indeed working with Google Tag Manager. We don’t need anything else, and so, you just simply click Done, and the only thing that you need to consider is this “index” number, because this is a sort of ID of course and that is what we are going to need when setting up the custom dimensions in Google Tag Manager.

Feeding Analytics with Google Tag Manager

And so the very first thing that we need to do when we are in Google Tag Manager is to check what the booking engine already outputs in terms of data and therefore since we want to track number of adults and number of children when people make a search, we need to see and to open up the search results page and see what is already there.

So let’s do it together with the preview mode. Google Tag Manager open and hit the preview mode.

We click on the Connect button and we give it a little bit of time in order to open up the page.

When the page opens up, we need to decide where exactly we are going to grab this information. In this case, in our case: number of adults and number of children. Visually speaking, we already see that this quick search form already has the value that we need.

So adults = 2 and children = 0.

So this is one option, meaning we will need to scrape the HTML structure of this form, of this element, reading this value and feeding Google Analytics accordingly with Google Tag Manager.

However, this is probably the last option that I would consider; first of all because it’s very technical and therefore you will need to know how to manage and how to deal with JavaScript code.

Second of all it’s even the least solid because the HTML structure may change over time and when doing so, what you did before in order to read this value may not work any longer.

There are multiple other options that we could go for and two of which are probably the one that I would suggest and the one that I’m going to show you right now.

The first one is by looking into a data layer. Now, a data layer is nothing but a piece of code in which the web developer, or the application developer, like in our case the booking engine developer, could store a whole bunch of information in order to make the life of those who will set up the tracking a lot easier.

However, it is not said that your booking engine is going to have a data layer, nor what kind of information you’re going to have. Each and every booking engine has a different data layer.

However, when present, a data layer is an essential part of Google Tag Manager because Google Tag Manager can read the data layer variables and therefore if we can work with a very structured data layer our life is going to be a lot easier and our tracking a lot more solid.

Let’s check whether first we have a data layer and what kind of information we have in it by simply going into the Tag Assistant Preview Mode tab and then we select the container event which is typically the event that fires automatically when the page loads.

And then do you see here? We have data layer option. If we click on it we see what our data layer is. And essentially this is saying that we have… no data layer.

Nowadays there are many booking engine out there in the market that deploy very structured and very complete data layer with a lot of information that we can work with.

You can do the same check by opening up the preview mode of the search results page of your booking engine and heading to this data layer tab and see what kind of data you have in there. And if you see data in there, it shouldn’t be difficult to identify the one variable that you’re looking for and then when so, just grab the name and then back in Tag Manager, Variables, you scroll down, click New Variable Configuration and you see we have Data Layer Variable: it’s a built-in variable type directly in Google Tag Manager. Just hit it and then under Data layer variable name you simply enter the value that you’ve seen in your data layer within your booking engine.

Of course give it a name like in this case let’s call it Data layer variable and then Adult Quantity and save. And that is it: you already have in this case the adult quantity directly as a variable that you can make use of very easily in any of your tasks.

If you’re in a situation where you cannot rely on a data layer because either you don’t have a data layer or because the information that you need to look for is not present in the data layer, then you will need to look into another way and the best alternative way is by looking into the URL of your booking engine. So open up again the booking engine page, the search results page of your booking engine and check the URL. Most of the time you will see everything that you need already in there.

In this page I’ve collected three different booking engine links with three different structures.

Now I have changed the main domain simply because I didn’t want to make any reference to any specific booking engine provider. However, despite the different structures you will notice that each link has a question mark.

And what’s most important to notice is that after each question Mark we have a whole bunch of URL parameters and if you pay closer attention to them you will see that we have a whole bunch of information that may be quite useful. Like in our case we’re looking for adults and children and there they are, total adults number two and total (in this case “bambini” in Italian) = zero. Anyway, we have the value that we need.

In the second example we only have adults and in the third example just a different name. But we have both values. So the beauty of Google Tag Manager is that now we can read we can instruct the Tag Manager to read those values and to save them and store those values as a variable to then feed our Google Analytics custom dimension.

So let’s see together how to do it.

This is our previous example and in the URL, as we can see we have the two variables that we need to download and read in Google Tag Manager.

So let’s go back to Google Tag Manager and create the variables. So variable configuration. This time we’re going to select URL and the only thing that we’ll need to define is the component type. As a matter of fact the URL is made of different parts. What exactly are we looking for?

Now we select the query which is essentially just a different way of saying URL parameters and then the query key, we go back to our values and we select each one of them. So in this case total adults. I just hit the copy back and here I paste it and there it is. I just give it a name “Adult” and save.

Now let us do the same thing with children.

So hit New. Again URL. I’m just going to name it first “Children” and again we’re going to select Query, and in the input field we’re going to get the variable name that we are interested into. So copy, back, query, paste and that’s it.

Now we have saved those two variables. Now the very first thing that we need to do is to check whether Tag Manager is reading properly those values.

So how to do it? We’re just going to refresh our preview mode. So let’s select again the container loaded event which is the one that fires when the page loads and then select the variables. And if we scroll all the way down we will see our two newly created variables, Adults and Children with the right values respectively, two and zero. Okay, so we refreshed our page.

So now let’s get back to our preview mode, select again the container loaded at the bottom of our event list and then select Variable. And now if you scroll all the way down we will see our two newly created variables URL, adults and children with respective values of two and zero. You see how in Google Tag Manager thinks and becomes so easy.

Now that we have our values, our variables, we have everything ready, the only thing missing is to set up a Tag, meaning we will need to send these values from Google Tag Manager to Google Analytics.

So let’s go back to Google Tag Manager and let’s create in the tag section a new tag, Tag Configuration we’re just going to select a Google Analytics Universal Analytics. Track type: it can be a page view, it can be an event. Now in this case, I’m just going to be using event for a very simple reason that I don’t want to change any other page view. I just have a page view for all other pages and I don’t want to change anything of that.

And so event, event category I can put anything that I want like Booking Search and then Google Analytics Settings we select our previously defined GA code or Google Analytics code. And now let’s tick this option “Enable overriding settings settings in this tag”: this will open up a whole bunch of other parameters. We don’t need to enter anything in the tracking ID because that remains unchanged.

What we need to open is the More Settings toggle and then as you can see, custom dimensions, and then add custom dimension. Now you see now we have two fields, index and dimension value. Now index: if you remember when we set up a custom dimension in Google Analytics, we were provided with an index number, in this case 1. And that is the number that we now need to use in Tag Manager in order to map the values that we’re going to be sending to these custom dimensions.

So back to Google Tag Manager, index 1 and dimension value we can simply hit the + icon and select our two variables, respectively URL Adults.

Variables in the context of Google Tag Manager are represented by curly brackets. All right, so that is perfectly fine if you see it that way. And then you may want to put a separator between adults and children like typically use a plus, but feel free to use like a – or / or whatever that is. And that is really it.

Now let’s get to the final part, the triggering. Now we want to send these values adults and children only when people hit the search results page in the booking engine. Now this of course may change depending on your booking engine. In this case, I know that the search result, the booking engine page is represented by this specific URL path.

All right. And that is exactly what I’m going to be using in order to define my page. And so I’m going to copy this value here. Or as you can see, let’s go back actually in the preview mode because we have already such values. So without you knowing what it is, but you can see we have a prebuilt or built-in variable which is Page Path and already have the value that I need to look into.

And that’s exactly what I’m going to be using in order to create the trigger. And so back to Google tag Manager. So, Trigger, in other words, when do we want to activate this tag? In the search results page, so I’m going to create a new trigger hitting the plus icon, I’m just going to call Search Result page; Trigger Configuration is a Page View; All Page Views? No, only the ones that have Page Path being equal… or let’s put Contains: premium-index-2-hotel.

You see, I took the value from the page path value in the preview mode because this defines the search results page of this specific booking engine and that’s exactly what I need as an information in order to set up our trigger.

So back to Google Tag Manager: I just hit the Save and this trigger is associated with our tag.

The really last thing that we need to do is to name our tag UA Event Booking Search and let’s save it. And when done we just need to test once again before setting everything live. So hit again the preview button.

So the page has refreshed. Now let’s get back again to our preview mode. And as we can see under Tags fired now we have the new tag UA event booking search, and if we click on it… actually we’ll need to select first the event and then click on it, in order to see the values that we have been sending. And as you can see custom dimension index one, dimension 2 + 0. Meaning value 2 + 0. So index one which is the value coming from Google Analytics and then the value of 2 + 0, so two adults and zero.

So let’s check directly in Google Analytics we have a real time area where we can see the events coming through and we can see our event category Booking Search being correctly recorded in our Google Analytics. We don’t see the values in here in this very moment because the custom dimensions are associated to the session and not necessarily viewable in the real time. However, now we have data value that we can use, for example in our custom reports. So for example, our customization area, custom report… We can create a new custom report.

And now Adults and Children, and here we have.

So Adults and Children is a dimension and we can see how many sessions, for example, did we have, how many users did we have, how many transactions did we have and so on and so forth. And so once we save it, we have our report up and running.

This is really it. I hope you enjoyed it. And yes, let’s see you again in the next video. Bye.


Share this post:

Leave a Reply

Follow Me On Social Media

Liked This Article?

Subscribe and get FREE access to all Premium posts.

Follow Alessandro on Linkedin

Digital Strategy & E-commerce Expert for Independent Hotels.

Need Help Getting More Revenue & Reducing Costs for Your Hotel?​

Let’s talk about it and see IF and HOW we can help.

Need Help Getting More Revenue & Reducing Costs for Your Hotel?

Let’s talk about it and see IF and HOW we can help.

Need Help Getting More Revenue & Reducing Costs for Your Hotel?​

Let’s talk about it and see IF and HOW we can help.

Need Help Getting More Revenue & Reducing Costs for Your Hotel?

Let’s talk about it and see IF and HOW we can help.


Blue Ocean Strategy Canvas

Download Your Blue Ocean Strategy Canvas for Free!


Surviving... then Thriving and Succeeding the Hotel Online Game Like These Hoteliers Did... in 3 Steps.


Access Your Free Copy Now! Enter your Name and Email address below

How to make the competition irrelevant - Blue Ocean Strategy for Hotels