Google Analytics issue - site search has no results

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
yeulih
Jr. Propeller Head
Posts: 3
Joined: Thu Feb 22, 2018 12:50 pm

Google Analytics issue - site search has no results

Post by yeulih »

Hello,

I have recently implemented Google Analytics in my HTML5 output. This worked great, as Google Analytics seems to tracking the visits with no issues.

I then implemented the Google Analytics site search functionality, using the instructions from https://mike.kelley.consulting/blog/how ... tml-output . It's been several months and unfortunately, I'm getting nothing when I view the Reports -> Site Search pages.

This is my code:

Code: Select all

		<!-- Global site tag (gtag.js) - Google Analytics -->
		<script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-########-#"></script>
		<script>
			window.dataLayer = window.dataLayer || [];
			function gtag(){dataLayer.push(arguments);}
			gtag('js', new Date());
			gtag('config', 'UA-########-#');
		/* ]]> */</script>
I added the GA script to my master page in the <body> section. From a previous forum topic it was indicated that it would work in either the <head> or the <body> section. (viewtopic.php?f=9&t=30141). Can anyone help diagnose why my site search isn't working? The only thing I can think of so far is that the GA code doesn't show up in my output trigger file (Flare uses default.htm by default), but I'm not sure why this matters as it seems to work for others.

Thanks in advance!
Last edited by yeulih on Thu May 31, 2018 8:53 pm, edited 1 time in total.
Psider
Propellus Maximus
Posts: 811
Joined: Wed Jul 06, 2011 1:32 am

Re: Google Analytics issue - site search has no results

Post by Psider »

I think your end script tag is in the wrong place (in the middle of you google script). Delete that whole line and make sure there is a single </script> tag after that gtag(config line.

yeulih wrote:Hello,

I have recently implemented Google Analytics in my HTML5 output. This worked great, as Google Analytics seems to tracking the visits with no issues.

I then implemented the Google Analytics site search functionality, using the instructions from https://mike.kelley.consulting/blog/how ... tml-output . It's been several months and unfortunately, I'm getting nothing when I view the Reports -> Site Search pages.

This is my code:

Code: Select all

		<!-- Global site tag (gtag.js) - Google Analytics -->
		<script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-########-#"></script>
		<script>
			window.dataLayer = window.dataLayer || [];
			function gtag(){dataLayer.push(arguments);}
			gtag('js', new Date());
		/* ]]> */</script>
			gtag('config', 'UA-########-#');
I added the GA script to my master page in the <body> section. From a previous forum topic it was indicated that it would work in either the <head> or the <body> section. (viewtopic.php?f=9&t=30141). Can anyone help diagnose why my site search isn't working? The only thing I can think of so far is that the GA code doesn't show up in my output trigger file (Flare uses default.htm by default), but I'm not sure why this matters as it seems to work for others.

Thanks in advance!
yeulih
Jr. Propeller Head
Posts: 3
Joined: Thu Feb 22, 2018 12:50 pm

Re: Google Analytics issue - site search has no results

Post by yeulih »

Oops, I copied it in two parts and accidentally mixed up the order. I will edit the original post to reflect the actual script as it appears in my Flare project.
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics issue - site search has no results

Post by NorthEast »

yeulih wrote: Can anyone help diagnose why my site search isn't working?
You've said that GA is tracking your visits, so there's nothing wrong with the actual GA code.

First, I would double-check that you've set up GA for site search tracking, as described in Mike's blog post.
You need to set Site Search Tracking - On, and enter Highlight as the Query parameter.

Next, what skin are you using?
The site search definitely works for the Top Nav skin (and presumably the new Side Nav), but I don't think it works for the Tripane skin.
Or at least it doesn't work for any of my sites that use Tripane.
yeulih
Jr. Propeller Head
Posts: 3
Joined: Thu Feb 22, 2018 12:50 pm

Re: Google Analytics issue - site search has no results

Post by yeulih »

Dave, thanks for the help! I'm indeed using a tripane skin, so that seems to be my issue. I was hoping for something easy, but it looks like that's not going to happen...I suppose that to make this happen I will need to use insert Javascript code.
I came across this forum topic when I was looking for more information on tracking site search: viewtopic.php?f=9&t=18356. Would this method still work?

I updated the code in the above topic to reflect the new gtag usage:

Code: Select all

    $(document).ready(function(){

       $('div.search-submit').click(function(){
          gtag('event','search',{document.getElementById('search-field').value});
       });

       $('input#search-field').keypress(function(event) {
               if (event.keyCode == 13) {
                   gtag('event','search',{document.getElementById('search-field').value});
               }
       });

    });
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics issue - site search has no results

Post by NorthEast »

yeulih wrote:Dave, thanks for the help! I'm indeed using a tripane skin, so that seems to be my issue. I was hoping for something easy, but it looks like that's not going to happen...I suppose that to make this happen I will need to use insert Javascript code.
I came across this forum topic when I was looking for more information on tracking site search: viewtopic.php?f=9&t=18356. Would this method still work?
Yeah, I'm not sure how to record the "Highlight" parameter with Site Search in a Tripane skin. I assume it doesn't work because the "Highlight" parameter (on the top level page) and the help topic you visit are on separate pages.

The script in that other post records search terms as events (rather than using the Site Search). Provided that you send the event in the correct format using gtag(), then I'd expect it to still work.
Psider
Propellus Maximus
Posts: 811
Joined: Wed Jul 06, 2011 1:32 am

Re: Google Analytics issue - site search has no results

Post by Psider »

So I've been doing some research into tripane and google analytics.

I think the reason the search can't be logged in GA in tripane is that the actual path and search is after a hash/pound sign, which GA throws away.
(This page states that it's thrown away and provides a gtag solution, but I'm not on gtag at the moment. And the images are broken, but you might be able to find them on the wayback machine. And I'm sure there are pages discussing the same or similar solutions.
https://www.beyond.com.au/blog/external ... ag-manager)

e.g
Address bar:
http://my.site.com/index.htm#My_awesome_widget.htm
http://my.site.com/index.htm#My_awesome ... ght=widget

What seems to be logged is the iframe location rather than the "page" location.

e.g
Address bar: http://my.site.com/index.htm#My_awesome ... ght=widget
Logged path: http://my.site.com/My_awesome_widget.htm

You can see both of these in the browser console using location.href and frames.topic.location.href respectively.
('topic' is the name of the content iframe)

I'm not quite sure if GA tracks the frame automagically or if it's something in the Madcap javascript somewhere.

I think Tripane is a form of Single Page Application. The URL changes but the page doesn't actually reload(?). And there's a page for developers about how to develop them for GA: https://developers.google.com/analytics ... plications

But I'm not a developer so I'm not quite sure what would be needed (I'll probably figure it out in a couple of months of mucking around. :p ).

And I wonder if this plugin would solve the issue:
https://github.com/googleanalytics/auto ... tracker.md

Anyway, it doesn't help with the original question, but maybe it'll help someone down the track.
abhatti
Jr. Propeller Head
Posts: 1
Joined: Mon Nov 26, 2018 10:49 am

Re: Google Analytics issue - site search has no results

Post by abhatti »

For Tripane, I was able to get GTM to work by doing the following:

In the Tripane flskn file, go to the Toolbar tab.
In the Custom JavaScript to include in toolbar page:, click Edit.
Add the following:

Code: Select all

/* This is the Google Tag Manager script */
$(document).ready(function () {
$('head').prepend(' <!-- Google Tag Manager --><script src="Resources/Scripts/googleanalytics.js"></script><!-- End Google Tag Manager -->');
});
Create the googleanalytics.js file in your Resources/Scripts folder with the following:

Code: Select all

(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
	new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
	j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
	'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-#######');

THEN add the googleanalytics.js file to your HTML5 output TOC. I have mine at the bottom of the TOC, conditioned to not be displayed. I believe the rationale for this was that the .js file was not being pulled in when the target was built, so we added it to the TOC to ensure it would be called in.

Hope that helps!
phillipkent
Jr. Propeller Head
Posts: 4
Joined: Fri Feb 02, 2018 9:32 am

Re: Google Analytics issue - site search has no results

Post by phillipkent »

Update for Flare 2019r2. I don't fully understand the behavior of the Tripane, but it uses URL fragments (i.e. text after '#' in a URL) for searches, and for some topic page views (but not all topic page views, so far as I can tell). Google Analytics does NOT track URL fragments by default, it deletes the # and everything following.

To enable handling of URL fragments you need to use Google Tag Manager (it seems can be done by GA alone, but I couldn't work it out). The GTM script needs to be put in the skin file ('Custom JavaScript in the Toolbar page'). If you do this, DO NOT put any tracking code in the master page. Here is what I have used:

Code: Select all

/* Google Tag Manager */
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
			new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
			j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
			'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
		})(window,document,'script','dataLayer','GTM-XXXXXXX);
/* End Google Tag Manager */
This script gets put into a file in the output: Resources/Scripts/Default/Scripts/SKIN-NAME.js (where SKIN-NAME will be the name of your skin), and it is loaded into every page of the HTML output, at the end of the <body> like this:

Code: Select all

 <script type="text/javascript" src="Resources/Scripts/Default/Scripts/SKIN-NAME.js">
        </script>
The suggestion above is to use an extra JS file in the project ('scripts/googleanalytics.js') to hold the GTM script, which is preferable because the GTM account number is not hard-baked into the skin file. But that JS file does not load into the HTML output and I couldn't work out how to do that.

For configuring GTM to handle fragments, see: https://webmasters.stackexchange.com/qu ... ent-in-url, https://www.simoahava.com/gtm-tips/trac ... -pageviews .
I set the GTM variable 'get path with fragment' to:

Code: Select all

function() {
  return window.location.pathname + window.location.search + window.location.hash.split('%3FTocPath')[0];
}
The 'split' there strips off the TocPath stuff at the end of the URL which is redundant for Google Analytics.
richardc66
Jr. Propeller Head
Posts: 3
Joined: Wed Mar 11, 2020 1:29 pm

Re: Google Analytics issue - site search has no results

Post by richardc66 »

The Mike Kelley blog posting detailing how/where/what script to add to enable search-term tracking no longer appears to be available online. Does anyone have a current version of the script that I can add to the head section of my master pages?

Thanks,

Rich




quote="Psider"]I think your end script tag is in the wrong place (in the middle of you google script). Delete that whole line and make sure there is a single </script> tag after that gtag(config line.

yeulih wrote:Hello,

I have recently implemented Google Analytics in my HTML5 output. This worked great, as Google Analytics seems to tracking the visits with no issues.

I then implemented the Google Analytics site search functionality, using the instructions from https://mike.kelley.consulting/blog/how ... tml-output . It's been several months and unfortunately, I'm getting nothing when I view the Reports -> Site Search pages.

This is my code:

Code: Select all

		<!-- Global site tag (gtag.js) - Google Analytics -->
		<script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-########-#"></script>
		<script>
			window.dataLayer = window.dataLayer || [];
			function gtag(){dataLayer.push(arguments);}
			gtag('js', new Date());
		/* ]]> */</script>
			gtag('config', 'UA-########-#');
I added the GA script to my master page in the <body> section. From a previous forum topic it was indicated that it would work in either the <head> or the <body> section. (viewtopic.php?f=9&t=30141). Can anyone help diagnose why my site search isn't working? The only thing I can think of so far is that the GA code doesn't show up in my output trigger file (Flare uses default.htm by default), but I'm not sure why this matters as it seems to work for others.

Thanks in advance!
[/quote]
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics issue - site search has no results

Post by NorthEast »

richardc66 wrote:The Mike Kelley blog posting detailing how/where/what script to add to enable search-term tracking no longer appears to be available online. Does anyone have a current version of the script that I can add to the head section of my master pages?
It isn't actually a script, you just use the Site Search feature that's available in analytics:

1. Open the site and go to the Admin tab.
2. In the View column, select View Settings.
3. Switch on Site search Tracking.
4. Enter Highlight as the Query parameter, and select Strip query parameters out of URL.

Obviously you need to first include the Google Analytics tracking code in your project.

This works for HTML5 Top Nav and Side Nav skins, but not Tripane.
richardc66
Jr. Propeller Head
Posts: 3
Joined: Wed Mar 11, 2020 1:29 pm

Re: Google Analytics issue - site search has no results

Post by richardc66 »

Thanks for your response, Dave!!! I turned on Site Search Tracking, as you describe, prior to your response. I had listed highlight and q (like this: highlight, q) in the Query Parameter field. But, based on other posts on the forum, I was under the impression that we also needed to include a section of script similar to this in the head section of my master pages:

(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','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-142461875-2','http://serviceconnect.support.cdk.com/h ... efault.htm'); ga('send', 'pageview');)(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXXXX','http://XXXXXXXXX.htm'); ga('send', 'pageview');

$(document).ready(function(){

$('div.search-submit').click(function(){
ga('send','event','Search','Search',document.getElementById('search-field').value);
});
$('input.search-field').keypress(function(event) {
if (event.keyCode == 13) {
ga('send','event','Search','Search',document.getElementById('search-field').value);
}
});
});

A few questions:

-- Is this extra code not necessary?
-- If it is necessary, does this code seem correct? I found this on the forum. Madcap Support helped me tweak it to accommodate some changes in Google's code.

Thanks MUCH in advance,

Rich

Dave Lee wrote:
richardc66 wrote:The Mike Kelley blog posting detailing how/where/what script to add to enable search-term tracking no longer appears to be available online. Does anyone have a current version of the script that I can add to the head section of my master pages?
It isn't actually a script, you just use the Site Search feature that's available in analytics:

1. Open the site and go to the Admin tab.
2. In the View column, select View Settings.
3. Switch on Site search Tracking.
4. Enter Highlight as the Query parameter, and select Strip query parameters out of URL.

Obviously you need to first include the Google Analytics tracking code in your project.

This works for HTML5 Top Nav and Side Nav skins, but not Tripane.
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics issue - site search has no results

Post by NorthEast »

The only script you need is the tracking code that you get from the Google Analytics admin site.
Make sure you get the latest 'gtag' code, not the 'ga' code in the first part of your script example.

Once you've added the GA code, then Site Search will work too - with no additional scripts required.

The second part of your script after the GA stuff is about how to track searches when using a Tripane skin, and isn't required for Top Nav or Side Nav skins.
richardc66
Jr. Propeller Head
Posts: 3
Joined: Wed Mar 11, 2020 1:29 pm

Re: Google Analytics issue - site search has no results

Post by richardc66 »

Dave Lee wrote:The only script you need is the tracking code that you get from the Google Analytics admin site.
Make sure you get the latest 'gtag' code, not the 'ga' code in the first part of your script example.

Once you've added the GA code, then Site Search will work too - with no additional scripts required.

The second part of your script after the GA stuff is about how to track searches when using a Tripane skin, and isn't required for Top Nav or Side Nav skins.


Thanks yet again, Dave, for the help. I have implemented your instructions, but I'm still not having any success. One issue I'm concerned about is the query parameter you suggested: highlight. The instructions I read about how to identify the query parameter make me think q (and not highlight) is the correct parameter. I have added both q and highlight in the parameter field and separated them using a comma. Still no luck. Any other recommendations?

Rich
techwriter31
Propellus Maximus
Posts: 551
Joined: Wed Mar 05, 2008 10:50 am

Re: Google Analytics issue - site search has no results

Post by techwriter31 »

I'm currently using both q and Highlight and have the Strip query parameters out of URL unchecked. This works for me.
sitesearch.png
You do not have the required permissions to view the files attached to this post.
Kellie
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics issue - site search has no results

Post by NorthEast »

richardc66 wrote:
Dave Lee wrote:The only script you need is the tracking code that you get from the Google Analytics admin site.
Make sure you get the latest 'gtag' code, not the 'ga' code in the first part of your script example.

Once you've added the GA code, then Site Search will work too - with no additional scripts required.

The second part of your script after the GA stuff is about how to track searches when using a Tripane skin, and isn't required for Top Nav or Side Nav skins.


Thanks yet again, Dave, for the help. I have implemented your instructions, but I'm still not having any success. One issue I'm concerned about is the query parameter you suggested: highlight. The instructions I read about how to identify the query parameter make me think q (and not highlight) is the correct parameter. I have added both q and highlight in the parameter field and separated them using a comma. Still no luck. Any other recommendations?

Rich
I'd imagine the site search should just work provided you've set up the google analytics code correctly.
So is the google analyics code working - do you see page views being recorded for your site?
lorynj
Propeller Head
Posts: 34
Joined: Mon Apr 23, 2018 6:17 pm
Location: Melbourne, Australia

Re: Google Analytics issue - site search has no results

Post by lorynj »

If you're interested in tracking what people are searching for, you use q as the query parameter. If you're interested in tracking what search results people are clicking on, you can track Highlight. But if you do track Highlight, then it'll interfere with your ability to get clean stats on the pages people are actually visiting.

I choose to track search queries, while ensuring that page visits are all captured uniformly.
analytics.png
You do not have the required permissions to view the files attached to this post.
Loryn Jenkins
Technical Writer and Consultant
Franchise Cloud Solutions
Post Reply