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!
Google analytics script showing up in search results
Re: Google analytics script showing up in search results
I put the analytics script at the end of the body section in my master page; i.e. after the topic body proxy.
Re: Google analytics script showing up in search results
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!
Re: Google analytics script showing up in search results
Put it in the header section..
Re: Google analytics script showing up in search results
It should go in the header section of your master page.
Re: Google analytics script showing up in search results
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
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
Re: Google analytics script showing up in search results
Each script is unique to that topic? I'm a bit confused about how you have your analytics set up...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
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>
Re: Google analytics script showing up in search results
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.
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.
Re: Google analytics script showing up in search results
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!
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
![Smile :)](./images/smilies/icon_smile.gif)
Thanks to all for your input!