Skip to content

Commit

Permalink
Correct Google Analytics generation code
Browse files Browse the repository at this point in the history
See #1786
  • Loading branch information
Gerrit0 committed Nov 13, 2021
1 parent 5957675 commit d6910ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# Unreleased

### Bug Fixes

- Corrected HTML generation for projects using Google Analytics, #1786.
- Ensured that the `<meta charset="utf-8" />` appears within the first 1024 bytes of generated pages, #1783.

### Thanks!

- @RunDevelopment

## v0.22.8 (2021-11-07)

### Features
Expand Down
17 changes: 10 additions & 7 deletions src/lib/output/themes/default/partials/analytics.tsx
Expand Up @@ -6,15 +6,18 @@ export function analytics(context: DefaultThemeRenderContext) {
const gaSite = context.options.getValue("gaSite");
if (!gaID) return;

const script = `
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', '${gaID}', '${gaSite}');
ga('send', 'pageview');
`.trim();

return (
<script>
(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','//www.google-analytics.com/analytics.js','ga'); ga('create', '{gaID}', '{gaSite}
'); ga('send', 'pageview');
<JSX.Raw html={script} />
</script>
);
}
1 change: 0 additions & 1 deletion src/lib/utils/jsx.elements.ts
Expand Up @@ -729,7 +729,6 @@ export interface JsxScriptElementProps extends JsxHtmlGlobalProps {
| "strict-origin-when-cross-origin"
| "unsafe-url";
src?: string;
text?: string;
type?: "module" | (string & {});
}

Expand Down

0 comments on commit d6910ff

Please sign in to comment.