track site search with gtm
When your site does not use the q=
query parameter.
Instead you have someting like this example.com/index/search/contact
then use following config in GTM
Go To Variables
- create new variable called
site search term
- select
regex table
as variable type - select
page path
as the input variable - click
add row
- for the pattern
^/index/search/(.*)
for the output$1
this pattern will store the value of the search in in the variable$1
- save the variable.
Create a tag
to send search term to analytics
- select tag config
- ga4 event as the tag type
- add measurement id
- add event name
view_search_results
Add event parameter to tag
- add parameter named
search_term
- for the value select the variable you created earlier
- now scroll down and select triggering
add the trigger
- add trigger called
search results
- add page view which fires on some views.
- select page path
- select condition to
matches regex
- add
^/index/search/(.*)
as the value (or whatever values your search result page uses)
the trigger ensures the event only fires on the search results page
This post is licensed under CC BY 4.0 by the author.