Search code examples
searchgoogle-analyticsgoogle-analytics-filters

Google analytics Site search is not working as expected


I just started using Google analytics for my website. I found that, enabling site search for a site is very easy as mentioned below,

enter image description here

But my site doesn't have the search term in the query string, instead it is part of the url as mentioned below,

https://mydomian.net/search#q=boxtest18

for some internal reason i cannot modify the code to append search term as querystring to url.

This article explained how to configure site search in GA, if Site Search Term Is Present in the URL: NOT As Query Parameter (Single Term).

When i tried, it doesn't seem working.

Below is my filter configuration.

enter image description here

What i'm doing wrong here?

Can i use the filter for this kind of url?

Is my regular expression correct?

Help me out here.


Solution

  • After digging into Google analytics and Google tag manager i found the solution. Solution was very easy in my case.

    For every search, search term was updating in the url fragment. In the below case, i searched for boxtest18 and url updated like below.

    https://mydomian.net/search#q=boxtest18

    For this, i had crerated a Tag in Google tag manager and triggered it on history change event. That resovled my problem.

    Here are the steps.

    1. In google tag manager i have added new tag and filled highlighted info. enter image description here

    2. Fragment value is a variable which i created. enter image description here

    3. For the new tag i have created the triggering event as shown below. enter image description here

    And make sure you have the tracking code script and Google tag manager script in your web page. That's it. Hope it helps someone.