How to track user search terms with Google Analytics

This forum is for all Flare issues not related to any of the other categories.
Post Reply
Mike Kelley
Propeller Head
Posts: 68
Joined: Fri Aug 22, 2014 12:24 pm

How to track user search terms with Google Analytics

Post by Mike Kelley »

Propeller-heads, I've written a new blog post detailing how you can track and capture what your users are searching for in your HTML outputs, with the help of Google Analytics. With search term tracking, you can better understand what your users are looking for and make improvements to your help system.

Google Analytics is free, so if you have HTML output, there's no reason not to do this!

http://mike.kelley.consulting/blog/how- ... tml-output

If you want to be notified when new blog posts are added to my site, I've developed an RSS feed you can use:
http://mike.kelley.consulting/blog/rss.xml

Happy search tracking!
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: How to track user search terms with Google Analytics

Post by NorthEast »

Thanks - looks a really neat solution, I've set it up in our analytics.

That will capture the search terms when you visit a topic from the search results.

Just bear in mind that it won't capture the search term if someone doesn't visit a topic.
So if people search for terms that they can't find in your help, then you won't know about those.
I find it useful to capture those terms too, as they can indicate if things are missing, or alternative terminology.
In order to get GA to work with Flare, you must add a link to Google's jsapi library before your custom GA code.
Why do you need the link to jsapi and what does that do?
Just I've used the standard GA code for ages, and it seems to work fine as it is.
Mike Kelley
Propeller Head
Posts: 68
Joined: Fri Aug 22, 2014 12:24 pm

Re: How to track user search terms with Google Analytics

Post by Mike Kelley »

Dave Lee wrote:Just bear in mind that it won't capture the search term if someone doesn't visit a topic.
So if people search for terms that they can't find in your help, then you won't know about those.
That's a good point. My previous solution was some JavaScript I wrote that transformed Flare's hash-based URL query to a regular URL query that GA could detect, and post it back to GA. If I wanted to capture the scenarios you indicate, that JavaScript would work. I just like this as a cleaner solution and my team hasn't really missed the extra searches yet.
Dave Lee wrote:
In order to get GA to work with Flare, you must add a link to Google's jsapi library before your custom GA code.
Why do you need the link to jsapi and what does that do?
Just I've used the standard GA code for ages, and it seems to work fine as it is.
When I originally set up GA, it gave me a link to the jsapi library, but the link was in a src="//google.com/jsapi" format which made Flare barf all over the build. I didn't know that GA works fine without it now.
ElaineB
Propeller Head
Posts: 21
Joined: Fri May 27, 2016 9:29 am

Re: How to track user search terms with Google Analytics

Post by ElaineB »

Question - are we required to use HTML5 output in order to make Google Analytics work? The company I work for wants a WebHelp output and they've used G.A. in RoboHelp and they want it to work in Flare without going to HTML 5.

is this possible?

I have the entire google code that I could insert into the master webhelp page - any thoughts or suggestions?

Thanks
Elaine
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: How to track user search terms with Google Analytics

Post by NorthEast »

ElaineB wrote:Question - are we required to use HTML5 output in order to make Google Analytics work?
No, GA will work in regular WebHelp too.
rstav
Jr. Propeller Head
Posts: 3
Joined: Thu Jun 29, 2017 9:32 am

Re: How to track user search terms with Google Analytics

Post by rstav »

Mike, this post is from a while ago, I know, but I found it useful almost a year later. Thanks!

I've set up Google Analytics on my doc site, but I did notice that I had to remove the link to Google's jsapi library to get the GA tagging to work properly.

Would you be willing to share the JavaScript you developed that transformed Flare's hash-based URL query to a regular URL query that GA could detect and post back to GA?

I'm interested in tracking user search where the user wasn't successful in finding what they were looking for.
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: How to track user search terms with Google Analytics

Post by NorthEast »

I track searches with no results for my Flare help sites.

I have it set up as follows:

* I create a search results page, which is a topic that contains a search results proxy.

* The search results page first loads the GA script, followed by this script:

Code: Select all

$(document).ready(function(){
	/* ----- record search terms with no results ------ */		
	if($(".total-results").length == 0) {
			/* not search results page */
	} else {
			/* check for any DOM changes in results number */
			$(".total-results").on('DOMSubtreeModified', function () {
				var totalResults = $(this).text();
				/* strip quotes from term string */
				var searchTerm = $(".query").text().replace(/\"/g, "");
				/* if results number equals zero, send analytics event */
				if (totalResults == "0") {
					ga('send', 'event', 'Search', 'No results', searchTerm);
				}
			});
	}
});
* Then I can go into Google Analytics and see these recorded as events, with category - "Search", action - "No results", label - the search term.
rstav
Jr. Propeller Head
Posts: 3
Joined: Thu Jun 29, 2017 9:32 am

Re: How to track user search terms with Google Analytics

Post by rstav »

Thanks for sharing, David.

I also found a way to capture search terms that don't result in users clicking on a page in Google Analytics without adding additional javascript.
I'm using Content Grouping in GA to analyze user behavior on different parts of our doc site, so I set up a Content Grouping with a rule definition for search queries.

The rule is defined like this:
Page contains /Search.htm?q=

When I view Site Content reports using Content Groups, I can see search terms listed in the page name.
For example, a search for "new account" shows up as Search=htm?q=new account in the report.

Thought I'd share in case anyone may find it useful in the future.
cdschroeder
Sr. Propeller Head
Posts: 189
Joined: Mon Feb 22, 2016 9:18 am
Location: Cincinnati, OH

Re: How to track user search terms with Google Analytics

Post by cdschroeder »

We are testing no results tracking, and found that search filters are causing issues. For example, we might get a notification that a search for "new topic" does not have any results, but the reason it doesn't have results is because the user applied a specific search filter.

Has anyone adapted search term tracking to also track search filters? I've found the code that highlights the active search filter, I just don't know the JS to put that information to good use.
search-filter.png
You do not have the required permissions to view the files attached to this post.
Casey

Image
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: How to track user search terms with Google Analytics

Post by NorthEast »

I know the filter is added as parameter to the URL:

.../SearchResults.htm?q=term&f=filter

So you could capture that, e.g. here the filterTerm variable is set to "None", or set as the filter term if one exists:

Code: Select all

var filterTerm = "None";
if (window.location.search.indexOf('f=') > -1) {
	filterTerm = location.search.split("f=")[1]; 
}
(Note - this is a very simple solution that assumes filter is the last parameter in the URL. It might need more a more robust solution if the URL format is likely to change.)

And include that filterTerm information when you send the event to GA:

Code: Select all

ga('send', 'event', 'Search - No results', filterTerm, searchTerm);
cdschroeder
Sr. Propeller Head
Posts: 189
Joined: Mon Feb 22, 2016 9:18 am
Location: Cincinnati, OH

Re: How to track user search terms with Google Analytics

Post by cdschroeder »

Thank you so much, Dave. We made a minor modification to your code, but this got us pointed in the right direction! I really appreciate your help.

In case anyone is interested, we found that we had to replace "search" with "href" for the URL to be read correctly:

Code: Select all

var filterTerm = "None";
if (window.location.href.indexOf('f=') > -1) {
filterTerm = location.href.split("f=")[1]; 
}
Casey

Image
Nina Esile
Sr. Propeller Head
Posts: 153
Joined: Tue May 05, 2009 1:07 pm

Re: How to track user search terms with Google Analytics

Post by Nina Esile »

Wondering if I should be able to see the Google Analytics code in my output? When I build, it seems to strip out the GA code. Is that possible?
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: How to track user search terms with Google Analytics

Post by NorthEast »

Nina Esile wrote:Wondering if I should be able to see the Google Analytics code in my output? When I build, it seems to strip out the GA code. Is that possible?
Yes, you should be able to see the GA code in the output.

It may not be included, depending on how/where you've added the code:
* Anything in the head section of a topic is not included in the output. If you want it in the head, it needs to be in the master page head section.
* Anything in the body section of a topic is included in the output.
Nina Esile
Sr. Propeller Head
Posts: 153
Joined: Tue May 05, 2009 1:07 pm

Re: How to track user search terms with Google Analytics

Post by Nina Esile »

* Anything in the head section of a topic is not included in the output. If you want it in the head, it needs to be in the master page head section.
* Anything in the body section of a topic is included in the output.
That's it, Dave. Thanks. I hadn't put it in the master page. I tried that and it worked.
Post Reply