Google Analytics woes...
-
- Propeller Head
- Posts: 50
- Joined: Tue Mar 05, 2019 2:43 am
Google Analytics woes...
Hi, all,
I'm trying to add google analytics to my Flare HTML5 TopNav output. (I'm using Flare 2019, btw)
Having read the Google Analytics info, and also from reading these forums, the recommendation is to put the Google tracking code in the Master Pages, in the Header section (Google say it should be immediately after the <head> opening tag...)
However, wherever I paste the google code in the master pages (beginning of <head>, end of <head>, beginning of <body>, end of <body>, and either by pasting the code itself, or a link to a .js file that contains the code), when I build the project, the output has no reference to any of the GA tagging.
If I paste the GA code into the <head> of a topic itself, then after building, that file will contain the GA tracking info... (which proves I have the code itself correct...)
Any ideas about what I'm doing that might be causing Flare to strip out, or ignore, the GA code when I add it into the Master Pages?
Many thanks all
Andrew
I'm trying to add google analytics to my Flare HTML5 TopNav output. (I'm using Flare 2019, btw)
Having read the Google Analytics info, and also from reading these forums, the recommendation is to put the Google tracking code in the Master Pages, in the Header section (Google say it should be immediately after the <head> opening tag...)
However, wherever I paste the google code in the master pages (beginning of <head>, end of <head>, beginning of <body>, end of <body>, and either by pasting the code itself, or a link to a .js file that contains the code), when I build the project, the output has no reference to any of the GA tagging.
If I paste the GA code into the <head> of a topic itself, then after building, that file will contain the GA tracking info... (which proves I have the code itself correct...)
Any ideas about what I'm doing that might be causing Flare to strip out, or ignore, the GA code when I add it into the Master Pages?
Many thanks all
Andrew
-
- Propeller Head
- Posts: 50
- Joined: Tue Mar 05, 2019 2:43 am
Re: Google Analytics woes...
OK, I've managed to solve it!
Its all to do with the strictness of how Flare checks the javascript. Flare sees "<script async src...> as invalid.
If I change this to "<script async="" src...> the individual topics see it as OK, but the master pages still don't understand it.
Edit that line to "<script async="async" src...>" and Flare suddenly starts adding the code into all the topics that use the masterpage...
<Slight update>
The above method seems to work if I add the full Google tracking code to each master page, but if I add it to a .js file, and link that .js file from each master page, it still doesn't work!
However, as I only use a few Master Pages, I can live with having embedded, rather than linked, .js code for this!
</Slight update>
Its all to do with the strictness of how Flare checks the javascript. Flare sees "<script async src...> as invalid.
If I change this to "<script async="" src...> the individual topics see it as OK, but the master pages still don't understand it.
Edit that line to "<script async="async" src...>" and Flare suddenly starts adding the code into all the topics that use the masterpage...
<Slight update>
The above method seems to work if I add the full Google tracking code to each master page, but if I add it to a .js file, and link that .js file from each master page, it still doesn't work!
However, as I only use a few Master Pages, I can live with having embedded, rather than linked, .js code for this!
</Slight update>
-
- Propellus Maximus
- Posts: 840
- Joined: Mon May 01, 2006 10:11 am
- Location: Inside California
Re: Google Analytics woes...
Sounds like a great idea for a knowledge base article
Richard Ferrell
Certified Madcap Trainer
Certified Madcap Trainer
Re: Google Analytics woes...
Agree with Richard, there is a huge thread about this very same issue and many people encounter issues with async vs async="" because of the strictness of XHTML. There really needs to be an FAQ thread on these forums.
-
- Propeller Head
- Posts: 50
- Joined: Tue Mar 05, 2019 2:43 am
Re: Google Analytics woes...
From my experiences, it also seems strange that the level of strictness varies depending on where you use the code...AlexFox wrote: many people encounter issues with async vs async="" because of the strictness of XHTML.
If you use async="", it seems to work in topics, but not in master pages (master pages seem to only be happy with async="async"!)
Re: Google Analytics woes...
I put the analytics code in a snippet, then put that in the body of the master page(s). I can confirm analytics="" works in this arrangement.WriterAndrew wrote:From my experiences, it also seems strange that the level of strictness varies depending on where you use the code...
If you use async="", it seems to work in topics, but not in master pages (master pages seem to only be happy with async="async"!)
Edit: that should read async="", not analytics=""
-
- Propeller Head
- Posts: 50
- Joined: Tue Mar 05, 2019 2:43 am
Re: Google Analytics woes...
As I have now managed to get GA working on my doc portal (portal currently restricted to only work from behind the company servers, due to "release" it next month...) and get test data coming back, for now, I think I'll leave it all as-is - however, if I have need to make changes in the future, I'll follow your suggestions!Dave Lee wrote:I put the analytics code in a snippet, then put that in the body of the master page(s). I can confirm analytics="" works in this arrangement.
Thanks for the feedback.
-
- Propellus Maximus
- Posts: 1979
- Joined: Tue Nov 28, 2006 11:18 am
- Location: Crossroads of the West
- Contact:
Re: Google Analytics woes...
We have the reference to our GA code (in a separate JS file) at the end of our master page, right before the </body> tag. It works for us. But I don't have the async part in my code. This is what our GA code looks like:
It is in a separate JavaScript file that is referenced from the Master Page, like this:
Code: Select all
// Google Analytics-provided code
(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-XXXXXXXX-X', 'auto');
ga('send', 'pageview');
Code: Select all
<script src="scripts/analytics.js">
</script>
Re: Google Analytics woes...
You're using the old 'ga' code, which was deprecated and replaced mid-2017 by the new 'gtag' code. If you set up analytics now, you'll get the 'gtag' code.doc_guy wrote:We have the reference to our GA code (in a separate JS file) at the end of our master page, right before the </body> tag. It works for us. But I don't have the async part in my code.
The new code is in this format (with async updated):
Code: Select all
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx-x"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxxx-x');
</script>
-
- Propellus Maximus
- Posts: 1979
- Joined: Tue Nov 28, 2006 11:18 am
- Location: Crossroads of the West
- Contact:
Re: Google Analytics woes...
Dave,
Is there a benefit to switching to the new format?
Is there a benefit to switching to the new format?
Re: Google Analytics woes...
It'll keep working when Google turns off ga() for good?
Seriously though I'm interested in the answer. From what I've read I *think* it's easier to deal with tags, but I don't use tags, so I'm not sure what that even means.
Seriously though I'm interested in the answer. From what I've read I *think* it's easier to deal with tags, but I don't use tags, so I'm not sure what that even means.
Re: Google Analytics woes...
The benefit is that your analytics will still work whenever Google stop supporting the old format, whenever that happens.doc_guy wrote:Dave,
Is there a benefit to switching to the new format?
I'm just pointing it out, as anyone setting up analytics right now (or in the last 2 years) will be provided with the 'gtag' code, not that 'ga' code.
-
- Sr. Propeller Head
- Posts: 133
- Joined: Sun Feb 03, 2013 6:01 pm
Re: Google Analytics woes...
Can I ask, how did you put the script into a snippet? And, subsequently, how did you insert the snippet into the body? I love this idea but I've tried doing these tasks multiple ways and it doesn't appear to work for me. If I inspect the HTML in a browser after Flare compiles the HTML5, the Google Analytics script isn't there.Dave Lee wrote:I put the analytics code in a snippet, then put that in the body of the master page(s). I can confirm analytics="" works in this arrangement.
I appreciate any advice on this. Thanks,
-jeff
Re: Google Analytics woes...
1. Open the master page.Chicago_HPT wrote:Can I ask, how did you put the script into a snippet? And, subsequently, how did you insert the snippet into the body? I love this idea but I've tried doing these tasks multiple ways and it doesn't appear to work for me. If I inspect the HTML in a browser after Flare compiles the HTML5, the Google Analytics script isn't there.Dave Lee wrote:I put the analytics code in a snippet, then put that in the body of the master page(s). I can confirm analytics="" works in this arrangement.
I appreciate any advice on this. Thanks,
-jeff
2. Add a blank paragraph at the end of the body section, select the paragraph, then click Create snippet.
3. Open the snippet, switch to Text Editor, and paste the Google analytics code.
4. Edit the code to read async=""
There was a typo in my old post - it's async="", not analytics=""
-
- Sr. Propeller Head
- Posts: 133
- Joined: Sun Feb 03, 2013 6:01 pm
Re: Google Analytics woes...
Thanks for the quick reply, Mike. In the Text Editor, do you replace the empty p tag with the script tag, or do you wrap the script tag inside the p tag?
Re: Google Analytics woes...
No problem, Barbara.Chicago_HPT wrote:Thanks for the quick reply, Mike. In the Text Editor, do you replace the empty p tag with the script tag, or do you wrap the script tag inside the p tag?
Either way should work.
-
- Sr. Propeller Head
- Posts: 133
- Joined: Sun Feb 03, 2013 6:01 pm
Re: Google Analytics woes...
In a hasty attempt to thank Dave Lee, Chicago_HPT clumsily wrote:Thanks for the quick reply, Mike.
LOL. Touché. Sorry, about that Dave.So Dave Lee slyly wrote:No problem, Barbara.
Thanks for your help. I have to dive deep into the nested divs that Flare builds into the compiled file to find it, but the GA code is there.
*doffs cap*
Cheers,
-jeff
Re: Google Analytics woes...
Can someone please encapsulate the solution here, or let me know re the issues I'm having - lot of back and forth and rather not try every single thing if someone can help
1. Google analytics says to place the tracking code into the head, so presume between <head> and </head>. But if I use Insert > Script from the xml editor, couple things go wrong:
a. there's no way to insert in the head tags that I can see - do it at the top and it goes after <body>
b. it inserts the old and useful '<![CDATA['
2. Are the solutions here about how to format in head, or keep in body and that works?
3. What are/is the solution?? few examples are shown but not clear which one worked - and only the start tag ", not where it ends (eg, 'src, then close it where?)
4. Maybe the dumbest of my dumb questions, but presume the script type is 'javascript', correct? covering the bases...
Disappointed this doesn't 'just work' as the info from both google and madcap is extremely minimal, as tho this should be the case
Thanks for any tips!
1. Google analytics says to place the tracking code into the head, so presume between <head> and </head>. But if I use Insert > Script from the xml editor, couple things go wrong:
a. there's no way to insert in the head tags that I can see - do it at the top and it goes after <body>
b. it inserts the old and useful '<![CDATA['
2. Are the solutions here about how to format in head, or keep in body and that works?
3. What are/is the solution?? few examples are shown but not clear which one worked - and only the start tag ", not where it ends (eg, 'src, then close it where?)
4. Maybe the dumbest of my dumb questions, but presume the script type is 'javascript', correct? covering the bases...
Disappointed this doesn't 'just work' as the info from both google and madcap is extremely minimal, as tho this should be the case
Thanks for any tips!
Re: Google Analytics woes...
Firstly, don't use Insert > Script in Flare, because that's for inserting javascript itself, but the code that Google Analytics currently provides is in HTML format with <script> tags.
So you just 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) Find the text async and change it to async="" (discussed earlier in the thread).
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.
So you just 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) Find the text async and change it to async="" (discussed earlier in the thread).
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.
Re: Google Analytics woes...
so, lot of conflicting advise, lol!
1> Google sez put inside 'head' tags - here you say body? madcap is silent on the issue....
2> madcap sez use async="asycn' but you just show empty quotes - same thing?
3> any tips best way to test? presume I just have to upload it to the live site and see if it shows up in the google analytics page. I have a local server but not sure how/whether I need to add it to the google tracking as it seems it will either work or not on the live site.
Fyi, published to my local site but looking at the page source and inspect there is nothing about google
thanks, and again tips appreciated
1> Google sez put inside 'head' tags - here you say body? madcap is silent on the issue....
2> madcap sez use async="asycn' but you just show empty quotes - same thing?
3> any tips best way to test? presume I just have to upload it to the live site and see if it shows up in the google analytics page. I have a local server but not sure how/whether I need to add it to the google tracking as it seems it will either work or not on the live site.
Fyi, published to my local site but looking at the page source and inspect there is nothing about google
thanks, and again tips appreciated
Re: Google Analytics woes...
1 & 2) What I've described is how I've got it set up in my own projects, so I know that it works. Other ways may work too, but I can't comment on those.
3) Google Analytics has a "Realtime" section where you can check it instantly.
3) Google Analytics has a "Realtime" section where you can check it instantly.