-
Notifications
You must be signed in to change notification settings - Fork 196
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 doesn't work with NueJS #175
Comments
Is If possible, could you also try to provide some (redacted) snippet that represents your GA code? |
I searched around and found this example code: <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script> And got this error: !! parse error layout.html
89 |
90 |
91 | // exec('`font-size:${_.size + "px"}`;', data)
92 | export function exec(expr, data={}) {
93 | const fn = new Function('_', 'return ' + expr)
94 | const val = fn(data)
^
SyntaxError: Unexpected token '.'. Expected a ';' following a class field.
at <parse> (:5:1)
at Function (native:1:1)
at exec (/home/username/.bun/install/global/node_modules/nuejs-core/src/fn.js:94:23)
at createComponent (/home/username/.bun/install/global/node_modules/nuejs-core/src/render.js:290:25)
at map (:1:11)
at /home/username/.bun/install/global/node_modules/nuekit/src/site.js:200:24 Which seems like the code is tried to be parsed as Nue Edit: Yep. I'm sure (at least for me): I added a Lines 92 to 96 in 83e96ac
And I this when running the dev server: class Impl {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
} |
@nobkd Txs for that, I was just about to add that. Yes, that's exactly the error I get. |
Just thinking about it, we might probably be able to quickly hack it by simply moving the second piece of hard coded script into another file and import that as well? But I dont want to do any further experimenting until I've established whether it works out of the box for anyone else. Otherwise I could be trying to fix a problem that is a side effect of something else. |
@nobkd Yeah, I tried manually adding it to and Nue just strips it out. Not sure what the render (transform) code in Nue looks like; i assume the blog gets converted to metadata and then rendered; I'm assuming there's no transform to pick up custom GA or script tags and add that to the meta data to make it into the final rendering. Just my initial thoughts. Both the two lines I added have no impact on any output. |
Actually I ran into problems like this too. Do we have workaround supporting inline |
This is a bug on the template engine, which treats |
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 <!-- Google Analytics -->
<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', 'TAG_ID', 'auto');
ga('send', 'pageview');
</script> You can alternatively use a <script client>
// hey
</script> Gets rendered as <script>
// hey
</script> |
Added docs for this. |
the docs link above is to localhost : actual link to docs is : https://nuejs.org/docs/reference/template-syntax.html#client-side-script-tags |
@tipiirai ![]() I manually created another starter blog
I then manually ran a build, Finally I edited the starter blog template for the brand new getting started nuejs, version 0.32, and added this to the default layout.html <main>
<script client>
alert('hello')
</script>
<slot for="content"/>
<blog-posts :posts/>
</main> After adding that, and saving. I run
|
Is there something else I have to do, to get access to or |
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... |
@nobkd
Questions
|
No, because the version check file name has not been updated in the source code. See my last comment: #175 (comment) It's the same file structure as yours. My commands for a small example:
|
@nobkd Your steps are basically the same as mine. But to be extra sure I ran your exact steps, and didn't get an alert, and F12 shows no <script> element. This could be a bun/package issue; It sounds like you're encountering an issue where the bun create nue@latest command is not installing the latest version of 'nue'. This could be due to a few reasons: Cache Issue: Sometimes package managers cache an older version. Try clearing the cache. Check the registry directly (like npmjs.com if 'nue' is an npm package) to see the latest version. I will investigate further in a few hours. Just in the middle of some work stuff I have to complete first. Looks like a good excuse to build that Cloudflare CICD build step, which basically will just be something like npm install bun Then I can test it on clean build image. If that works, then I just have to ask clippy how to clear my bun caches etc on my dev box. If it doesnt work on a clean build agent, then it could be one of the other problems mentioned by clippy. |
Can you check from |
I'm not using any packages or node modules. I dont have a packages.json file in my project. I check the version of nue that is being used by calling i.e. some bizarre situation where calling from command line |
@tipiirai Actually, here's a simpler demo of the problem. step 1; add in the script tag to template.html That's it, that's all you need to do, to see the bug; here's what I get, and you can clearly see the version of nue that is running via the console output, as well as the parsing error ![]() |
For some reason you don't have the latest |
@tipiirai damn, answer is right there... bun install nue <-- instead of --> bun install nuekit |
here's the problem I think
Now, 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. Options / suggestions to fix
|
@tipiirai ![]() |
works flawlessly on Cloudflare build agent with bun & npx@tipiirai here's some more pieces to the puzzle; bun update && npx nue build --production 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. This spike projects includes a cheesy alert box, just to prove that using Below is a redacted extract of the build log from Cloudflare after doing a git push on main branch.
The build takes
|
Great that it at least works on other devices. +
I agree, that the command does not fit to the
On your side on both points there +
That's just really weird... Can you share what system you are on? Like operating system (and distribution) or so?
May I ask why you use
lol 😂 |
Awesome work guys! I'm thinking of bundling Nue JS server components inside Nuekit later so that Nue JS only consists of client-side reactive parts. Nue JS is super buggy atm, and I think we should offer React (maybe Svelte) alternatives for building single-page apps. Not that this would solve the Bun install issue here. Just thinking aloud. |
@tipiirai I have Google Analytics working on my blog using the latest NueJs. closing, |
I can't find any way to add GA to a NueJS website/blog.
I've tried three approaches
<head>
element.<main>
in a raw<script>
tag.<html>
as described here : https://nuejs.org/docs/concepts/layout-components.html#root-layoutAll three approaches just crash with
unexpected token error
.I'm hoping I've done simply obviously wrong.
The text was updated successfully, but these errors were encountered: