In this video, you will learn how to track what people are searching for within your
website using GA4, Google Analytics 4.
I will show you how to use the automatic site search tracking
in GA4 using query parameters.
And I will show you how to track what people search for if you don't have any
query parameters available in your URLS.
Hey there!
I'm Benjamin from Loves Data, and I'm here to help you get the
most out of Google Analytics.
Tracking what people search for within your website can provide
some really valuable insights.
It can help you identify gaps in content, navigation issues, and
ideas for new products and services.
Okay, let's get started!
The first thing you need to do is figure out how your
website's search function works.
I encourage you to open up your website and follow along.
We're currently looking at my demo site, so let's search for something
. I'm going to search for 'contact'
We can now see the search results page . And let's take a look at the URL
for this page . We can see the URL for the page includes a query parameter of
'Q' which is used to provide the search results.
So we can see 'Q', then 'Equals', and then 'Contact', which is what we searched for.
If we then change 'Contact' to something else, like, 'Email' . And
then press 'Enter' . We can see
the page loads again and this time we're seeing search results on our website for
'Email' . This tells us that the query parameter of 'Q' is definitely providing
the search results on our website.
So we can use this to configure the site search reports in Google Analytics.
I want to highlight, that 'Q' is one of the most common query parameters used
for website search functions, but your query parameter might be different.
Other common query parameters are 'term', and 'search term' . So
take a moment to check the URL for your website's search results.
You might have a different query parameter.
And if you're not sure what what query parameter is used for your search
function, then perform a search like we just did, but on your website.
You need to look for the term you searched for and then just before the
term you should see an equals sign.
Before this, you should see a character, or word, and before this, you should
see a question mark or an ampersand.
The character or word between the question mark or ampersand and the
equals sign is your query parameter.
Okay, we're about to head to Google Analytics, but I want to mention, that
if you didn't see a query parameter in your URL, then we will cover how you can
track your search function in a moment.
Now let's head to Google Analytics . We need to navigate to 'Admin' . Then
we select 'Data Streams' . And open the data stream for our website . Now
let's click the configuration icon under 'Enhanced Measurement' . And I want you
to check that 'Site Search' is enabled . This option will automatically track the
search function on your website based on a number of pre-defined query parameters.
We can check the query parameters that Google Analytics will automatically
use by clicking 'Show Advanced Settings' . And we can see that 'Q'
is listed here, so we're good to go!
If the query parameter for your search function isn't listed,
then add a 'comma' at the end, and then enter your query parameter.
For example, if you found that 'term' was your query parameter, then add
a comma . Then enter 'term' . And click 'Save' . Google Analytics will
now begin to identify the term query parameter and use this to report
on your website's search function.
If you performed a search and you don't have a query parameter for your website's
search function, then you'll need to take a different approach to track what
people search for within your website.
Let's say you searchd for 'contact' and the URL for your search results page
looked like one of these examples . We can see the term we searched for,
which is 'contact', but this time it's included in the URL like a sub-folder.
If you see something like this, then you'll need to use Google Tag Manager
to adjust the URL so that it looks like a query parameter for Google Analytics.
Let's head to Google Tag Manager to configure this . And
let's select 'Variables'
Now let's create a new variable . Let's name the variable 'Site
Search Term' . And let's select 'Regex Table' as the variable type
Now let's select 'Page Path' as the input variable . And let's click 'Add Row'
. The in-built page path variable will include everything after the domain name.
We can then use a regular expression to identify the search term in our URLs.
For example, let's say the URL on our website after we searched
for 'contact' included 'forward slash', 'index', 'forward slash',
'search', 'forward slash', 'contact'
Then we can use this to configure our variable in Google Tag Manager.
Continuing this example, we would enter 'caret', 'forward slash', 'index',
'forward slash', 'search', 'forward slash', 'open parenthesis', 'full stop',
'asterisks', 'close parenthesis' . As the pattern . Then for the output,
we would enter 'dollar sign', 'One'
What this variable does is it looks for the URL based on our pattern on the left.
Then it stores the value in the parenthesis, and then
just outputs this value.
Let's save the variable
Now we need to create a tag to send the search term to Google Analytics.
Let's navigate to 'Tags' . And
let's create a new tag . Let's name the tag 'Google Analytics GA4 Site Search'
And
let's select 'Tag Configuration' . Now let's select 'GA4 Event' as the
tag type . We need to select our existing GA4 configuration tag . And
then for the event name, we need to enter 'view', 'underscore', 'search',
'underscore', 'results' . Now let's select 'Event Parameters' . Click
'Add Row' . And let's enter 'search', 'underscore', 'term' as the name
Now let's select the variable we just created as the value . Now we need to
scroll down and select 'Triggering' . Let's click the plus sign on the top
right corner to create a new trigger . Let's name the trigger 'Search Results'
Let's select 'Trigger Configuration' . And let's choose 'Page View' as the
trigger type . Now let's select 'Some Page Views' . And using the drop-down,
let's choose 'Page Path' . Then 'Matches Regex' . And let's enter the
same pattern we used for our variable.
Let's enter 'caret', 'forward slash', 'index', 'forward slash', 'search',
'forward slash', 'open parenthesis', 'full stop', 'asterisks', 'close parenthesis'
And let's save the trigger . The trigger that we've created will mean that our GA4
tag only fires on the search results page.
Now we can save the tag . You can now preview your container to check
that everything works as you expect.
And when you're ready you can publish the changes to your
website by clicking 'Submit'.
Okay, now I'm going to show you how you can track your website's search function
if you don't have a query parameter and you can't see the term you searched for
in the URL of your search results page.
If this is the case for you, then the first thing I recommend is checking
the way your search function works.
To do this, head to the page where you started your search.
Then I want you to view the source code for the page and look for the form that is
used for your website's search function.
If the form looks like this . Then you can try changing the
method from 'post' to 'get'.
This will mean your form will now look like this
Then when you perform a search, you should see the query parameter in
the URL of the search results page.
You can then use the very first technique we covered to track what people are
searching for within your website.
If you can't change the method for your form or changing the method to 'get'
doesn't provide a query parameter in the URL, then you can use Google Tag Manager
to capture the search terms people use.
Let's head back to my demo site to look at one approach we can use
to do this . We're still looking at the search results on my site.
And let's imagine that there is no query parameter in the URL.
In this case, we could make use of the page title to capture
what people have searched for.
Looking at the page title, we can see it includes our search term
However, it also includes the name of our website after the search term, so we
will need to clean this up a bit so that we only report on the actual search term.
Let's head back to Google Tag Manager do this . And let's navigate to
'Variables' . Let's create a new custom variable . Let's name the variable
'Site Search Term From Page Title'
And let's select 'Variable Configuration' . Now let's choose 'Custom JavaScript'
as the variable type . And I'm going to enter a simple JavaScript function
for the variable . This function gets the title of the page, and then removes
the name of the website from the title to get the search term . You will just
need to modify this with any value you need to remove from your page title
Now let's save the variable . And let's navigate to 'Tags' . Let's create a
new tag . Let's name the tag 'Google Analytics GA4 Site Search From Page Title'
And let's select 'Tag Configuration' . Now let's select 'GA4 Event' as the
tag type . We select our existing GA4 configuration tag . And then we
enter 'view', 'underscore', 'search', 'underscore', 'results' as the event
name . Now let's select 'Event Parameters' . Click 'Add Row' . Let's enter 'search',
'underscore', 'term' as the name
Now let's select the variable we just created as the value . Now we need to
scroll down and select 'Triggering' . Let's click the plus sign on the top right
corner to create a new trigger . Let's name the trigger 'Search Results' . Let's
select 'Trigger Configuration' . And let's choose 'Page View' as the trigger type
Now let's select 'Some Page Views' . And using the drop-down, let's choose 'Page
Path' . Then 'Matches Regex' . And I'm going to enter 'caret', 'forward slash',
'search' as the value . You might need to adjust this for your search results page.
Now let's save the trigger . The trigger that
we've
created will mean that our GA4 tag only fires on the search results page.
Now we can save the tag . Now let's click 'Preview' . And
let's perform a search
Now let's select the 'Tag Assistant' tab . And we can see our GA4 event tag has fired
And we can check the value of our variable
This shows us that we've captured the search term we entered
from the title of the page.
Finally, I want to show you how to report on the search terms people have
entered as they've searched your website.
Let's head to Google Analytics to take a look . We navigate to 'Explore'
And let's create a new blank report
Let's name the report 'Search Terms' . And let's add a dimension . Let's
search for 'search term' . This is a default dimension that's available in
GA4, so you just need to enable this dimension . And click 'Import' . We
can then enable metrics for our report . Let's search for and enable
'Event Count' . And click 'Import'
You can then drag 'Search Term' under 'Rows' . And any metrics you would like to
include under 'Values' . You will now be able to report on the search terms people
have used to search within your website.
Overall, the easiest way to track your website's search function is
using enhanced measurement, as we covered at the start of this video.
However, as we've seen, there are other options you can use if this
doesn't work for your website.
Are you tracking site search in GA4?
I'd love to know!
Let me know in the comments below.
And if you haven't already, please take a moment to subscribe to my
channel for all of my latest tutorials.
Thanks for watching and I'll see you in the next video!