Google Analytics woes...

This forum is for all Flare issues not related to any of the other categories.

Google Analytics woes...

Postby WriterAndrew on Mon May 13, 2019 2:33 am

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
WriterAndrew
Propeller Head
 
Posts: 25
Joined: Tue Mar 05, 2019 2:43 am

Re: Google Analytics woes...

Postby WriterAndrew on Mon May 13, 2019 2:51 am

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>
WriterAndrew
Propeller Head
 
Posts: 25
Joined: Tue Mar 05, 2019 2:43 am

Re: Google Analytics woes...

Postby Richard Ferrell on Mon May 13, 2019 10:45 am

Sounds like a great idea for a knowledge base article
Richard Ferrell

Certified Madcap Trainer
Image
Richard Ferrell
Propellus Maximus
 
Posts: 837
Joined: Mon May 01, 2006 10:11 am
Location: Inside California

Re: Google Analytics woes...

Postby AlexFox on Tue May 14, 2019 2:41 am

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.
AlexFox
Sr. Propeller Head
 
Posts: 127
Joined: Thu Oct 19, 2017 1:56 am

Re: Google Analytics woes...

Postby WriterAndrew on Tue May 14, 2019 4:04 am

AlexFox wrote: many people encounter issues with async vs async="" because of the strictness of XHTML.


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"!)
WriterAndrew
Propeller Head
 
Posts: 25
Joined: Tue Mar 05, 2019 2:43 am

Re: Google Analytics woes...

Postby Dave Lee on Tue May 14, 2019 5:44 am

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"!)


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.

Edit: that should read async="", not analytics=""
Dave Lee
Master Propellus Maximus
 
Posts: 5657
Joined: Mon Mar 05, 2007 8:33 am
Location: UK

Re: Google Analytics woes...

Postby WriterAndrew on Tue May 14, 2019 6:22 am

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.


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!

Thanks for the feedback.
WriterAndrew
Propeller Head
 
Posts: 25
Joined: Tue Mar 05, 2019 2:43 am

Re: Google Analytics woes...

Postby doc_guy on Tue May 14, 2019 11:26 am

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:
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');


It is in a separate JavaScript file that is referenced from the Master Page, like this:
Code: Select all
<script src="scripts/analytics.js">
                </script>
User avatar
doc_guy
Propellus Maximus
 
Posts: 1947
Joined: Tue Nov 28, 2006 11:18 am
Location: Crossroads of the West

Re: Google Analytics woes...

Postby Dave Lee on Tue May 14, 2019 11:39 pm

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.


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.

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>


If you use events, you also use the 'gtag()' function instead of 'ga()'.
Dave Lee
Master Propellus Maximus
 
Posts: 5657
Joined: Mon Mar 05, 2007 8:33 am
Location: UK

Re: Google Analytics woes...

Postby doc_guy on Wed May 15, 2019 9:47 am

Dave,

Is there a benefit to switching to the new format?
User avatar
doc_guy
Propellus Maximus
 
Posts: 1947
Joined: Tue Nov 28, 2006 11:18 am
Location: Crossroads of the West

Re: Google Analytics woes...

Postby Psider on Wed May 15, 2019 5:39 pm

It'll keep working when Google turns off ga() for good? :P

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.
Psider
Propellus Maximus
 
Posts: 595
Joined: Wed Jul 06, 2011 1:32 am

Re: Google Analytics woes...

Postby Dave Lee on Wed May 15, 2019 11:25 pm

doc_guy wrote:Dave,

Is there a benefit to switching to the new format?


The benefit is that your analytics will still work whenever Google stop supporting the old format, whenever that happens.

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.
Dave Lee
Master Propellus Maximus
 
Posts: 5657
Joined: Mon Mar 05, 2007 8:33 am
Location: UK

Re: Google Analytics woes...

Postby Chicago_HPT on Mon Sep 23, 2019 10:05 am

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.

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.

I appreciate any advice on this. Thanks,
-jeff
Chicago_HPT
Propeller Head
 
Posts: 70
Joined: Sun Feb 03, 2013 6:01 pm

Re: Google Analytics woes...

Postby Dave Lee on Wed Sep 25, 2019 12:24 am

Chicago_HPT wrote:
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.

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.

I appreciate any advice on this. Thanks,
-jeff


1. Open the master page.
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=""
Dave Lee
Master Propellus Maximus
 
Posts: 5657
Joined: Mon Mar 05, 2007 8:33 am
Location: UK

Re: Google Analytics woes...

Postby Chicago_HPT on Wed Sep 25, 2019 5:56 am

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?
Chicago_HPT
Propeller Head
 
Posts: 70
Joined: Sun Feb 03, 2013 6:01 pm

Re: Google Analytics woes...

Postby Dave Lee on Wed Sep 25, 2019 6:21 am

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?


No problem, Barbara.

Either way should work.
Dave Lee
Master Propellus Maximus
 
Posts: 5657
Joined: Mon Mar 05, 2007 8:33 am
Location: UK

Re: Google Analytics woes...

Postby Chicago_HPT on Wed Sep 25, 2019 7:17 am

In a hasty attempt to thank Dave Lee, Chicago_HPT clumsily wrote:Thanks for the quick reply, Mike.

So Dave Lee slyly wrote:No problem, Barbara.

LOL. Touché. Sorry, about that Dave. :oops:

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
Chicago_HPT
Propeller Head
 
Posts: 70
Joined: Sun Feb 03, 2013 6:01 pm


Return to Flare's General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests