Google Analytics Events and Tracking User-Entered Searches

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Events and Tracking User-Entered Search

Post by NorthEast »

Liv_W wrote:I am using the HTML 5 top nav skin, I just inserted the script into the master pages' bodies using Flare's Insert > Script and reloaded it. Is there a delay? I don't see results in Real Time yet?
There are two scripts - have you included both?

The script from Google Analytics needs to be placed before my script (to record the search terms).


Also, presumably you are testing this from a live website where you know Google Analytics already works?
Liv_W
Propeller Head
Posts: 20
Joined: Thu Dec 19, 2013 1:16 pm
Location: Cincinnati, OH

Re: Google Analytics Events and Tracking User-Entered Search

Post by Liv_W »

I have Google Analytics up and running and I see myself in there in real time. It's the search that I am struggling with. As I wrote before, I have tried multiple versions of this with the script in different spots. Below is the full topic page. Any thoughts on what I am missing would be appreciated.
Thanks,
Liv

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="7" MadCap:lastHeight="266" MadCap:lastWidth="1179">
    <head>
        <meta charset="utf-8" />
        <meta name="description" content="" />
        <meta name="author" content="" /><title></title>
        <link href="../Stylesheets/MainStyles.css" rel="stylesheet" type="text/css" />
        <script>
			(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
			(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
			m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
			})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

			ga('create', 'UA-77382901-1', 'auto');
			ga('send', 'pageview');
			
		   
		</script>
    </head>
    <body>
        <div class="content">
            <div id="contentBody">
                <div class="row collapse">
                    <div class="sideContent">
                        <div class="clearfix">
                            <MadCap:topicToolbarProxy />
                        </div>
                    </div>
                    <MadCap:breadcrumbsProxy />
                    <MadCap:bodyProxy />
                    <p> </p>
                    <p> </p>
                    <p class="feedback">Did you find this topic helpful ? Do you have suggestions ? We'd love your <script type="text/javascript">/*<![CDATA[*/var email=('liv.wessel@qvidian.com');
var subject = "Feedback from Topic: " + document.title;
document.write('<a href="mailto:' + email +
'?subject=' +subject+ '">' + 'feedback' + '<'+'/a>');
/*]]>*/</script>!</p>
                    <p>
                        <script type="text/javascript">/*<![CDATA[*/	$(document).ready(function(){
      
			/* FLARE SEARCH BOXES */
			/* add event handler for when search button is clicked */
			$('div.search-submit').click(function(){
			/* get search term from input box (input.search-field), which related to -this- at parent sibling level */
			var searchterm = $(this).parent().siblings('.search-field').val();
			ga('send', 'event', 'Search', 'SearchFor', searchterm);
			});

			/* add event handler for when press Enter (key 13) in search box  */
			$('input.search-field').keypress(function(event) {
			if (event.keyCode == 13) {
			/* get search term from -this- input box (input.search-field) */
			var searchterm = $(this).val();
			ga('send', 'event', 'Search', 'SearchFor', searchterm);
			}
			});/*]]>*/</script>
                    </p>
                </div>
            </div>
        </div>
    </body>
</html>
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Events and Tracking User-Entered Search

Post by NorthEast »

Not sure - it worked for me, and at least one other person.

However, that solution wasn't my preferred method, and isn't what I'm using myself.
I'm tracking searches from the search results page, as mentioned here: viewtopic.php?f=9&t=18356&start=25#p119605
doc_guy
Propellus Maximus
Posts: 1979
Joined: Tue Nov 28, 2006 11:18 am
Location: Crossroads of the West
Contact:

Re: Google Analytics Events and Tracking User-Entered Search

Post by doc_guy »

So I've been poking at this for the last week or so. I think I've found a solution that works for us. Maybe somebody who knows more can tell me why this is a bad solution...

I went to the Admin page, and clicked View Settings.

Image

Then I set my search parameter to be "Highlight".

Image

And I'm getting results:

Image

And I can even see what page they were on when they searched:

Image

Am I missing anything by not going to the javascript route identified earlier in this thread?
Paul Pehrson
My Blog

Image
Liv_W
Propeller Head
Posts: 20
Joined: Thu Dec 19, 2013 1:16 pm
Location: Cincinnati, OH

Re: Google Analytics Events and Tracking User-Entered Search

Post by Liv_W »

Thanks. I hope that works; it's so much simpler. I tried this before I posted here, except that I used "search" as the parameters and didn't get anything. I Just tried it with "highlight." Did it take a awhile for you to get the results or was it instant? It looks like you are looking at the Site Search > Overview Page, is that correct?
Thanks,
Liv
doc_guy
Propellus Maximus
Posts: 1979
Joined: Tue Nov 28, 2006 11:18 am
Location: Crossroads of the West
Contact:

Re: Google Analytics Events and Tracking User-Entered Search

Post by doc_guy »

Yes and yes. Make sure you change your date to include today (it doesn't include today by default). I see my info usually within an hour or so.
Paul Pehrson
My Blog

Image
Liv_W
Propeller Head
Posts: 20
Joined: Thu Dec 19, 2013 1:16 pm
Location: Cincinnati, OH

Re: Google Analytics Events and Tracking User-Entered Search

Post by Liv_W »

It worked! :D You made my day. Thank you so much.
Liv
mikey_mack
Jr. Propeller Head
Posts: 5
Joined: Fri Sep 02, 2016 5:57 am

Re: Google Analytics Events and Tracking User-Entered Search

Post by mikey_mack »

This worked perfectly for me! I have my Flare output integrated into our LMS, and I'm able to track searches now. However, I'm unable to get zero-result search terms pulled up. Has anyone been able to figure that out?
flicstar
Jr. Propeller Head
Posts: 1
Joined: Mon Apr 18, 2016 9:39 pm

Re: Google Analytics Events and Tracking User-Entered Search

Post by flicstar »

Thanks for this code. Can you tell me if it tracks zero search results? That is, search terms that return zero results - so that you can improve your content accordingly.
Psider
Propellus Maximus
Posts: 811
Joined: Wed Jul 06, 2011 1:32 am

Re: Google Analytics Events and Tracking User-Entered Search

Post by Psider »

I could be wrong, but I think @doc_guy 's method of adding highlight in the GA Admin query parameters won't log the search until a search result is clicked? That is :
1. type something in the search bar.
2. press search.
3. click search result link
4. google logs the search term.

Whereas what we want is for the search to be logged at step 2?
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Events and Tracking User-Entered Search

Post by NorthEast »

Psider wrote:I could be wrong, but I think @doc_guy 's method of adding highlight in the GA Admin query parameters won't log the search until a search result is clicked? That is :
1. type something in the search bar.
2. press search.
3. click search result link
4. google logs the search term.

Whereas what we want is for the search to be logged at step 2?
When you set up Site Search in GA, you could record the "q" parameter instead of "Highlight".
I think that should record all the initial search terms, although at the expense of knowing whether people clicked on a result.

Alternatively, you could also record the search terms as events - as discussed earlier in this same post:
viewtopic.php?f=9&t=18356&start=25#p119638
Post Reply