Google analytics script showing up in search results

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
RBOWES
Propeller Head
Posts: 17
Joined: Mon May 20, 2013 1:25 pm

Google analytics script showing up in search results

Post by RBOWES »

I'm inserting GA script into each topic in my help system. If I put the script within the body tags, right at the top (before the <H1> heading), I get the page hit data I need. BUT when the user opens the help and does a search, the search results show the GA script right under the topic name.
If I put the script within the head tags, where everyone says it should go, Google can't find it -- I don't get any GA data -- but the search is fine (no GA script appears in the results).

Any thoughts on how to make GA see the script when its in the head tags? OR how I can prevent the script from showing up in the search results if I put the script in the body tags?

This is an HTML5 output.

Thank you!
NorthEast
Master Propellus Maximus
Posts: 6375
Joined: Mon Mar 05, 2007 8:33 am

Re: Google analytics script showing up in search results

Post by NorthEast »

I put the analytics script at the end of the body section in my master page; i.e. after the topic body proxy.
RBOWES
Propeller Head
Posts: 17
Joined: Mon May 20, 2013 1:25 pm

Re: Google analytics script showing up in search results

Post by RBOWES »

Thanks, I'll try that! The script isn't actually in the master page. Each script has a unique event label for the specific topic, so I have to put it into the topic itself. However, I will try moving it to the end of the topic and see if that solves the problem(s). Thanks for your feedback!
ronakshah
Jr. Propeller Head
Posts: 2
Joined: Mon Feb 27, 2017 12:17 am
Contact:

Re: Google analytics script showing up in search results

Post by ronakshah »

Put it in the header section..
Martin_B
Propeller Head
Posts: 20
Joined: Wed Mar 15, 2017 10:34 am

Re: Google analytics script showing up in search results

Post by Martin_B »

It should go in the header section of your master page.
RBOWES
Propeller Head
Posts: 17
Joined: Mon May 20, 2013 1:25 pm

Re: Google analytics script showing up in search results

Post by RBOWES »

Thanks for the feedback about the header section. Unfortunately when I try that, Google Analytics doesn't recognize the script. That is, I don't get any GA data.

And since each script is unique to each topic, I can't put it into a master page either.

Does anyone have thoughts on why GA wouldn't recognize the script in the header tags? I can't figure it out.

Thanks,
Rebecca
Martin_B
Propeller Head
Posts: 20
Joined: Wed Mar 15, 2017 10:34 am

Re: Google analytics script showing up in search results

Post by Martin_B »

RBOWES wrote:Thanks for the feedback about the header section. Unfortunately when I try that, Google Analytics doesn't recognize the script. That is, I don't get any GA data.

And since each script is unique to each topic, I can't put it into a master page either.

Does anyone have thoughts on why GA wouldn't recognize the script in the header tags? I can't figure it out.

Thanks,
Rebecca
Each script is unique to that topic? I'm a bit confused about how you have your analytics set up...

I do recall running into issues placing the code in the header, below is the code I used in the end, perhaps that will help:

Code: Select all

 <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async="async" src="https://www.googletagmanager.com/gtag/js?id=YOUR ID HERE">
        </script>
        <script>
			window.dataLayer = window.dataLayer || [];
			function gtag(){dataLayer.push(arguments);}
			gtag('js', new Date());
 
			gtag('config', 'YOUR ID HERE');
		</script>
NorthEast
Master Propellus Maximus
Posts: 6375
Joined: Mon Mar 05, 2007 8:33 am

Re: Google analytics script showing up in search results

Post by NorthEast »

Generally speaking, in HTML a script can be placed in either the head or body section - the GA script works fine in either location, and I use it in the body.

In your case, the script isn't working because scripts in the head section of a topic are removed in the output - view the output topic in a text editor, and you'll see the script isn't there.
It would work in the head section of a master page, but not a topic.
So for scripts in a topic, add them to the body, not the head.
RBOWES
Propeller Head
Posts: 17
Joined: Mon May 20, 2013 1:25 pm

Re: Google analytics script showing up in search results

Post by RBOWES »

Thanks so much for the clarification about not being able to use scripts in the head tags for each TOPIC (as opposed to master pages).

I have moved the script back to within the body tags, but placed it at the end of the body section, as previously suggested. It now works fine :) . Google Analytics can find it and the script is not showing up in the search results.

Thanks to all for your input!
Post Reply