• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

RH 2019: Google Analytics + Master Pages

Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

I've inserted Google Analytics tracking code into the header/footer of master pages in RH 2017 and older, without issue. Trying to do the same with a brand new project created in RH 2019 and am having trouble.

 

If I insert the following code (I've replaced my tracking id with Xs for this post) in the header of a master page, as directed by Google:

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

gtag('config', 'XXXXXXXXX');
</script>

 

RoboHelp identifies the following error:

The attribute  [ async ]  must have a value.

Invalid character  s

 

Additionally, RoboHelp won't let me switch from the master page's code-view to its edit-view. Instead, it pops up a "Parse Error" dialog at the bottom right corner of RH stating:

Line: 6, Column: 15, Message: Invalid character s

 

Finally, while RoboHelp will allow me to save the change, if I attempt to create a new topic using this master page, the Google Analytics script/code is omitted from the header of the NEW topic. Note: I've also tried this with the footer; the behavior/result is the same.

 

Thoughts?

TOPICS
New UI , Scripting

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

RoboHelp 2019 you said

 

Classic or the new baby?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

New.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

On the Madcap forums, async always causes an error in Flare.

 

Change it to async="" and it shouldn't throw an error any more.

 

EDIT: That's recommended by the scripting guru on the madcap forums. But if it doesn't work try asyn="async" as per w3 schools https://www.w3schools.com/tags/att_script_async.asp

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

Removing "src" and going with just "async" resolved the RoboHelp error. Thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

Don't remove src, otherwise it won't work at all.

 

This is the change:
<script async="" src="https://www.googletagmanager.com/gtag/js?id=XXXXXXXXX"></script>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Fixed the async/src line. Thank you!

 

Last issue. Google advises inserting the Google Analytics (GA) script between <head>  </head>

I was hoping to deploy the GA script via RoboHelp master pages, so when I create a new topic, the script is auto-added (this is a new project). And similarly, if I decide to remove GA from the project, I could simply remove it from the master page header and it'd be removed from all the corresponding topics. However, in RoboHelp, the Master Page topic headers and footers are actually implemented via <div data-region="header"> </div> and <div data-region="footer"> </div>. I can insert the GA script in one of those (and new topics get it - and likewise remove it from the master page and it's removed from the same topics), but does anyone know if GA will work, since it's not in the <head> section, as they advise?

 

Or, am I going to need to actually insert the GA script in the <head> section of topics - in which case my only options for automating the insertion/removal will be via duplicating an existing topic (that has it) and/or a carefully crafted global search and replace procedure (e.g., using FAR HTML's search and replace tool or Notepad++ (long-time RH user, never trusted their search and replace tool, but maybe it's improved over the last 15 years and is now on par with those others))? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

I believe the old ga() code used to work when added to the master page header or footer, but I'm not currently using gtag, master page header footers or RH2019 (new or otherwise) so can't comment definitively. You might need to do a test release to confirm.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

Hi,

 

The correct place to put the script tag would be inside <head> tag of Master Page, not inside <div data-region="header"> or footer. The Master Page header and footer regions become actually part of Topic's Visible Content.

However as of now, RH 2019 doesn't copy <script> tags from Master Page <head> tag into Topics. We will fix this issue in upcoming release soon.

Please track the issue here: https://tracker.adobe.com/#/view/RH-6359.

 

Regards,
Vikas Singla

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

Amebr and Vikas, 

 

Thank you for the info! Looking forward to this getting patched - I'll work around it in the meantime!

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

@vikassingla As I remember, in RH11 entering the script in the master page "header" div adds the script into the project (into the topic header div, not into the project head tag) and the google analytics code works. I always switched to code view to add it, but I think using Insert > Script might also have added it as long as the cursor was in the right spot? I'd have to check though.

I did a quick test in RH2019 New adding a fake script into the header div using code view, and that is added into the output in a similar spot.
Adding the script in to the master page <head> tag never worked.

Not saying this is the right way, just describing how RH previously worked and still appears to.

If you have more specific information about the latest gtag script, I'd appreciate it.

 

@RoboFan, it might be worth checking that adding the code into the header div copies it to the output like I describe. And test that it sends data from a website to google if you can. 🙂

 

On a side note, I feel like last time I looked, the advice for the analytics code was really confusing and there is information floating around from 3 different script versions ago. I thought last time I looked that I even saw advice to put the script code just above the closing body tag. As I said, confusing. I do think it's worth testing if you can.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

Thank you Amebr for trying out gtag script in RH 2019. You have explained correctly that when added in header region of Master Page, it would work fine in Topics.

 

Google recommends putting the script tag in <head> tag of HTML files, so to achieve the same, RH 2019 needs to copy <script> tags from <head> section of Master Pages into Output Topics' <head>. That is the part we will be fixing.

 

However, @RoboFan you can go ahead with adding <script> tag in Master Page header region div. It will be included in final output topic, except the fact that it will be inside <body> of topic, not inside <head>.

As Amebr has tried out, it should still work fine.

 

Regards,
Vikas Singla

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

In older RH version projects, I have a GA script set up in the footer (<?rh-region_start type="footer">) of master pages - and it worked: that is, it was auto-created in new topics based on that master page *AND* it generated data in Google. However, I never did much with it (beyond initially confirming that it worked). I did notice that the code for that older GA script is fairly different from the new GA script (see my initial post in this thread) I generated for my new RH2019 project. Here's the older script:

 

<?rh-region_start type="footer" style="width: 100%; position: relative;" ?>
<script type="text/javascript">(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-#########', 'auto');
ga('send', 'pageview');</script>
<?rh-region_end type="footer" ?>

 

I'll have to play around with these more.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

LATEST

Let us know how it goes. 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
RoboHelp Documentation
Download Adobe RoboHelp