nue: Google analytics doesn't work with NueJS
I can’t find any way to add GA to a NueJS website/blog.
I’ve tried three approaches
- Tried adding it to the
<head>element. - Tried adding it at the top of the
<main>in a raw<script>tag. - Lastly, I tried following instructions on controlling layout yourself, and defining the entire root layout from
<html>as described here : https://nuejs.org/docs/concepts/layout-components.html#root-layout
All three approaches just crash with unexpected token error.
I’m hoping I’ve done simply obviously wrong.
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Comments: 29 (23 by maintainers)
the docs link above is to localhost : actual link to docs is : https://nuejs.org/docs/reference/template-syntax.html#client-side-script-tags
Added docs for this.
Pushed out a new Nue JS/Nuekit versions (0.3.1 and 0.3.2) where this issue is resolved. When a script tag has any attribute, such as
typeit is passed for the client as is. For example:You can alternatively use a
clientattribute which passes the script for the client as is and also removes the attribute so that the HTML stays clean. ie.Gets rendered as
@tipiirai I have Google Analytics working on my blog using the latest NueJs. closing, txs for the quick responses.
works flawlessly on Cloudflare build agent with bun & npx
@tipiirai here’s some more pieces to the puzzle; I started a new project from scratch, and just like above, it didn’t work. But this time I created a new Cloudflare Pages project and used this very complicated build pipeline below
And configured the build output directory in Cloudflare dashboard, and it works flawlessy; …well, fast and flawlessly! <-- I trademark that!! …lol
that will be a great tagline, Fast and flawlessly!
I digress, … so we know it works properly on a clean build machine, and that we have at least 1 person reporting an issue of upgrading to latest packages and dependancies, (me) and for some reason Bun is failing to update. Here’s the proof it’s working; https://fetish-pond-diving.divecode.co.uk/
This spike projects includes a cheesy alert box, just to prove that using
<script client>now works.Below is a redacted extract of the build log from Cloudflare after doing a git push on main branch.
The build takes
140ms, and the full site deployment, including CDN cache invalidation takes a further0.93s(930ms), excluding the time it takes for a git push to actually trigger the build, which in my experience is around 3 to 4seconds. Though that’s including the full round trip of how long it takes for the web UI to receive notification, so it’s obviously less than that value.@tipiirai Just finished testing; Sadly running
bun install nuekit@latestand using local packages, does not fix the problem. See screenshot. I will test next on clean build machine with Cloudflare build agent.here’s the problem I think
nueand making the name of the tool different from the name of the packageNow, if at any time in the future, perhaps 3 months from now a user needs a new feature because it’s all moved on quite a bit, then lets say 90% of the users look at their command line, and think … .I need to update “nue”… yknow, that command /utility I keep running. So they run bun install nue@latest which it does now when they run nue, it keeps on using nue from the first gloally installed nuekit package.
Options / suggestions to fix
The version-check wasn’t updated in the code: https://github.com/nuejs/nue/blob/master/packages/nuekit/src/init.js#L21-L28
That’s so weird. For me, it just works… Tested with v0.3.2 and v0.3.3…