Skip to content

Wrong GA script injection - script is inserted in the body as text #699

Description

@voiceapiai-dev

hi
first of all - thanks for this tool and OSS contributions

Desctiption

today I've decided to use it for my project https://github.com/voiceapiai/ralertsinua, and when I configured analytics settings I found that google tag script injection is broken - script is inserted in the body as text

image

How to reproduce:

  • remote: find broken script text visible at https://voiceapiai.github.io/ralertsinua/ at the very bottom of the screen
  • local - add analytics configuration according to the docs, run oranda build, find broken injection in generated index.html - script is inserted in the body as text

Possible solution:

according to Google, this is the code one need to insert at the website (notice 2 script tags):

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

  gtag('config', 'G-TCJ5D14XV4');
</script>

but this line

format!("window.dataLayer = window.dataLayer || []; function gtag(){{dataLayer.push(arguments);}} gtag('js', new Date());gtag('config', '{}');", self.tracking_id)

doesn't have HTML <script> tag, and thus the string is being inserted directly in the body

if possible, I would like to contribute and help to solve this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions