Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Analytics not working #45

Open
carriewright11 opened this issue Nov 30, 2023 · 11 comments
Open

Google Analytics not working #45

carriewright11 opened this issue Nov 30, 2023 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@carriewright11
Copy link
Contributor

Describe what is not working with the course

The Google Analytics may not be working as well - a couple of weeks ago I moved it in a commit. Can you please fix this @howardbaek ?

@carriewright11 carriewright11 added the bug Something isn't working label Nov 30, 2023
@carriewright11
Copy link
Contributor Author

carriewright11 commented Nov 30, 2023

This was
the PR #42

@howardbaik
Copy link
Contributor

The Google Analytics ID is correct. I see the difference is where the GA_Script.Rhtml file is included in _output.yml. I see that you had tried in_header: GA_Script.Rhtml and you weren't able to render locally. Maybe we can stick the GA_Script.Rhtml next to before_body?

before_body: [GA_Script.Rhtml, assets/big-image-itcr.html]

@carriewright11
Copy link
Contributor Author

carriewright11 commented Dec 5, 2023

@howardbaek can you please check if this new location fixed it?

@howardbaik
Copy link
Contributor

I see the PR corresponding to this issue was merged, so closing this issue.

@carriewright11
Copy link
Contributor Author

@howardbaek does this mean we confirmed that the new location works for us to see interactions now on google analytics?

@howardbaik howardbaik reopened this Dec 5, 2023
@howardbaik
Copy link
Contributor

I checked the google analytics for this course, and it doesn't seem to be working.

@howardbaik
Copy link
Contributor

howardbaik commented Dec 5, 2023

I've not deeply looked into how OTTR renders bookdown (do you know @cansavvy?), but maybe the reason is that I had only made the changes and didn't rmarkdown::render_site(encoding = 'UTF-8')?

That's what I do in this commit 51a0111

@howardbaik
Copy link
Contributor

howardbaik commented Dec 7, 2023

All these courses below put GA_Script.Rhtml inside before_body,

And their GAs are responsive, so I'm assuming that's the correct location. However, I've noticed a couple other websites with the GA_Script inside in_header.

In the first website, the GA Script is named GA_Script.Rhtml. In the second website, its named GA_Script.html. Strange that there are two different extensions.

@carriewright11 Do you remember what you were seeing when rendering locally?

@howardbaik howardbaik changed the title ["Problem"] Google Analytics Google Analytics Dec 7, 2023
@howardbaik howardbaik changed the title Google Analytics Google Analytics not working Dec 7, 2023
@howardbaik
Copy link
Contributor

howardbaik commented Dec 8, 2023

(I wasn't involved in the original development of OTTR, so this may be why I'm confused.)

Why do the GA_Script.html files in OTTR-generated websites contain html elements in addition to the Google tag code, seen below:

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

To my understanding, the above code needs to be placed before the closing <head> tag (https://stackoverflow.com/questions/41376989/how-to-include-google-analytics-in-an-rmarkdown-generated-github-page) and the way we do this in bookdown is using the in_header option (https://bookdown.org/yihui/bookdown/yaml-options.html).

If we include the above code inside the <head> element of our rendered html pages (using the in_header option), do we need the additional html elements like <body> or <html> in the GA_Script.html files?

@carriewright11
Copy link
Contributor Author

Hi @howardbaek - so glad you are looking at this and figuring out the consistency differences and what is needed.

@carriewright11 Do you remember what you were seeing when rendering locally?

This was the error:
Error in if (title == x2) return(head) : the condition has length > 1
Calls: ... split_chapters -> build -> sub -> is.factor -> prepend_chapter_title
Execution halted`

I tried running it locally with the in_header option again and reproduced the error and indeed if I remove <body> and <html> it renders and the error goes away. Although possibly redundant, this did not cause an error before - so the way in_header is handled may have changed?

@howardbaik
Copy link
Contributor

@carriewright11 What function/button did you run when you ran it locally?

A possibly separate question: I am digging deep into OTTR and bookdown and it seems like we are using the "Knit and Merge" (K-M) method to render a book since we set new_session: yes in this line. Is there a specific reason we are using the K-M method instead of the M-K method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants