Google Analytics Config

This forum is for all Flare issues not related to any of the other categories.
Post Reply
IPRO_JB
Propeller Head
Posts: 13
Joined: Mon Jan 29, 2018 1:31 pm

Google Analytics Config

Post by IPRO_JB »

Hi Everyone,
I have an HTML5 system and am trying to get Google Analytics up and running. So far, it does not appear to be functional. Here's how I went about setting up the code.

1) I copied and pasted, using the internal text editor for Flare, the Google Analytics tracking code in the <head> tag of the master page assigned to a group of topics in my help system. The code was:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/j ... "></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-xxxxxxxx-1');
</script>

2) I had to make a slight change, which was to change async to ascync="" otherwise I get the error message unexpected token at line 5 position 17. expected "="

3) I ran a build and posted it to our site.

4) I went to the Analytics site and went to the Real Time section and then clicked around on the site and it just said "active users on site right now 0"

The only possible hiccip is that, our help pages are password protected, they're located on our customer portal which the customer has to log in to. Is there something about that fact that will impact GA's ability to track my pages?

Any help would be much appreciated.
Thank you!!
Julie
Psider
Propellus Maximus
Posts: 811
Joined: Wed Jul 06, 2011 1:32 am

Re: Google Analytics Config

Post by Psider »

Maybe try the snippet idea at the end of this post?
viewtopic.php?f=13&t=27204
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Config

Post by NorthEast »

Psider wrote:Maybe try the snippet idea at the end of this post?
viewtopic.php?f=13&t=27204
Yeah - the difference is that I include the GA script in the body (not head), by including it in the master page.
I haven't tested it in the head section.

Other that that, have you checked for errors in the browser? (press F12 and check the console)
Kt_123
Jr. Propeller Head
Posts: 8
Joined: Tue Jun 02, 2015 9:37 pm

Re: Google Analytics Config

Post by Kt_123 »

IPRO_JB, did Google Analytics work for you?

I want to add GA with HTML5 Help. The help system requires a user login. Also, the HTML5 Help is context sensitive and is integrated with the application.
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Config

Post by NorthEast »

Using a user login should make no difference - it'll work as long as your help can run the GA script and talk to Google's servers.

Adding GA script inside the body definitely works. Just copy and paste the code supplied by GA, and change async to aysnc="".
Kt_123
Jr. Propeller Head
Posts: 8
Joined: Tue Jun 02, 2015 9:37 pm

Re: Google Analytics Config

Post by Kt_123 »

Thank you, Dave. :D

I am also assuming that GA will work with context sensitive HTML5 Help that is integrated with the application.
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Config

Post by NorthEast »

Kt_123 wrote:Thank you, Dave. :D

I am also assuming that GA will work with context sensitive HTML5 Help that is integrated with the application.
Yes, when a page loads, it'll run the GA script and record the page view in analytics.
It doesn't matter if the page is opened by clicking a link, or direct from CSH.

I'd also recommend setting up site search in GA to record searches - it's very easy. Described in this article:
https://mike.kelley.consulting/blog/how ... tml-output
Smriti
Jr. Propeller Head
Posts: 5
Joined: Tue Oct 16, 2018 2:48 pm

Re: Google Analytics Config

Post by Smriti »

Hi There,

I'm facing a similar problem. Any suggestions or ideas would help.
I have setup my google account and added the Tracking code to 3 of my master pages before closing the head tag.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-hhhhhh-h">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-hhhhhhh-H');
</script>

I then generated my output without any errors and then published to Madcap Central. Here's the Public URL:

However, when I check the real-time users, then It shows "no hits" or 0 Active Users. While I know that it is being used.

Any idea about what I did wrong?

Thanks
Smriti
Last edited by Smriti on Tue May 28, 2019 7:29 am, edited 1 time in total.
livent
Jr. Propeller Head
Posts: 7
Joined: Thu Feb 02, 2017 1:14 pm

Re: Google Analytics Config

Post by livent »

I've added the following analytics code righter after the <body> tag.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async="" src="https://www.googletagmanager.com/gtag/j ... "></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-xxxxxxxxx-x');
</script>

When I try building, the html5 gets stuck trying to resolve links in output files.
I also tried placed the Analytics code just before the closing </body> tag and the same thing happens.
gsm1
Propeller Head
Posts: 24
Joined: Wed Oct 05, 2016 4:46 pm

Re: Google Analytics Config

Post by gsm1 »

Dave Lee wrote:
Kt_123 wrote:Thank you, Dave. :D

I am also assuming that GA will work with context sensitive HTML5 Help that is integrated with the application.
Yes, when a page loads, it'll run the GA script and record the page view in analytics.
It doesn't matter if the page is opened by clicking a link, or direct from CSH.

I'd also recommend setting up site search in GA to record searches - it's very easy. Described in this article:
https://mike.kelley.consulting/blog/how ... tml-output

As of 7-24-2020 Mike Kelly's link isn't accessible.
daphna
Propeller Head
Posts: 36
Joined: Fri Feb 03, 2006 1:00 pm

Re: Google Analytics Config

Post by daphna »

Is the code in this thread used with SideNav or TopNav outputs?
Here's the code I am referring to:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async="" src="https://www.googletagmanager.com/gtag/j ... "></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-xxxxxxxxx-x');
</script>

The reason I am asking is that we are just switching to a SideNav setup. In our legacy Tripane outputs, we used a different type of code, which does not now render results. I am wondering if we need to change the code in our master pages. Here is what we used in the tripane outputs:


<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', '<MadCap:variable name="target_variables.analytics_UA" />', 'auto');
ga('send', 'pageview');

</script>
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Config

Post by NorthEast »

The Google Analyitcs code works on all HTML5 skin types - it makes no difference if it's Tripane, Top Nav or Side Nav.

The second piece of code you're using in your Tripane output is using Google's old "ga" code format, which was replaced in 2017 by their "gtag" code which is your first piece of code.
So I'd recommend using the newer "gtag" format because Google has deprecated the old "ga" format and it will stop working in the future.

So you need to:
1) Open your master page, and switch to Text Editor view.
2) Paste in the code from Google Analytics in the body section before the closing </body> tag.
3) Make sure you change async to async="" - if you don't, Flare will say there's an error in the code (because it's not valid XHTML).

If you have several master pages, it's easier to put that code in a snippet, and insert the snippet in all your master pages.
daphna
Propeller Head
Posts: 36
Joined: Fri Feb 03, 2006 1:00 pm

Re: Google Analytics Config

Post by daphna »

I've put the code in the body of my master page, including verifying that I saw async=""

I generated the target and verified that the GA code was propagated to topics after I genrated the target. However, we are not getting any hits on the GA dashboard.

Are there any specific settings that are necessary on the GA side? Or any other advice to get things working?

Thanks in advance.
atreloar
Jr. Propeller Head
Posts: 2
Joined: Fri Jan 04, 2019 12:00 pm

Re: Google Analytics Config

Post by atreloar »

We recently set up GA and we only saw results when placing the tag within the <head>.

We also attempted using a snippet, but during the build process the snippet moved into the <body> area, which caused it to not be picked up by GA, so we ended up manually adding it to each master page within the <head> area.
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Google Analytics Config

Post by NorthEast »

I don't think you can use snippets in the head section.

The analytics code works perfectly fine in the body section - I've been using it in all my projects like this for many years.
Post Reply