Analytics
2.3K members online now
2.3K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Site search not working for Single Page Application

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Site search settings is not working for a Single Page Application (SPA) built on top of Angular, unless a user hits the search url directly by typing it in the browser. 

 

e.g http://xyz.com/search?searchTerms=findme

Configuration :  queryParamter is set to "SearchTerms". 

 

Generica user flow : 

a. user visits : xyz.com

b. user enters a key word "findme" in the search box

c. and the search results are displayed with the url http://xyz.com/search?searchTerms=findme

  ( This is a SPA application, so technically there is no page view is being triggered).

 

Please suggest how do we capture search keywords. Would it work, if we were to configure Universal Analytics page view with a custom event trigger, based on the url change ? Or please suggest how would Site search work for SPA applications.

 

Thanks, 

 

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by Bronwyn V (Top Contributor)
August

Site search not working for Single Page Application

Top Contributor
# 4
Top Contributor

Hi @ven b if using GTM then some changes need to happen to the initial idea.

 

Instead of the initial code use something like this:

dataLayer.push ({

'event':'trackPage',

'page':'/search?searchTerm=something'

});

 

Then in GTM use custom event trackPage as the trigger for the GA pageview tag.

 

Create a dataLayer variable using key page.

 

In GA pageview tag under Fields to set use page on the left and assign the dataLayer variable created in previous step as the value.

 

Hope it helps!

 

Kind regards,

Zorin

Web analyst @ escapestudio.net

View solution in original post

Site search not working for Single Page Application

Top Contributor
# 2
Top Contributor

Hi @ven b you really need the additional pageview which will carry on the path and query param holding the searchTerm (note qp is case sensitive so make sure you follow through here!Smiley Happy

 

Use a custom trigger from your app which would just pass on:

ga ('send', 'pageview', '/search?searchTerm=something'); 

 

And you are set to go!

 

Kind regards,

Zorin

Web analyst @ escapestudio.net

Re: Site search not working for Single Page Application

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks much Zonrin for your prompt response. 

 

Do i need to configure anything in the Google Tag Manager, like using this a trigger for triggering analytics tracking code or will this take care of everything by itself

 

Use a custom trigger from your app which would just pass on:

ga ('send', 'pageview', '/search?searchTerm=something'); 

 

Marked as Best Answer.
Solution
Accepted by Bronwyn V (Top Contributor)
August

Site search not working for Single Page Application

Top Contributor
# 4
Top Contributor

Hi @ven b if using GTM then some changes need to happen to the initial idea.

 

Instead of the initial code use something like this:

dataLayer.push ({

'event':'trackPage',

'page':'/search?searchTerm=something'

});

 

Then in GTM use custom event trackPage as the trigger for the GA pageview tag.

 

Create a dataLayer variable using key page.

 

In GA pageview tag under Fields to set use page on the left and assign the dataLayer variable created in previous step as the value.

 

Hope it helps!

 

Kind regards,

Zorin

Web analyst @ escapestudio.net

Site search not working for Single Page Application

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hello 
I am also having same issue for site search , but in my case i am using Universal analytics tag to get page views which run on history change trigger as it is a angular SPA but no site search parameters are passed through it only page path is sending to analytics. i think there might be some solution for passing the parameters also , and i can not afford to have custom event for sitesearch 

can any one please tell how to solve this issue 

Thanks in advance 

 

 

Shivam 

Site search not working for Single Page Application

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hello 
I am also having same issue for site search , but in my case i am using Universal analytics tag to get page views which run on history change trigger as it is a angular SPA but no site search parameters are passed through it only page path is sending to analytics. i think there might be some solution for passing the parameters also , and i can not afford to have custom event for sitesearch 

can any one please tell how to solve this issue 

Thanks in advance