Open Jeroen999 opened 1 year ago
Hey @Jeroen999,
Thanks for reaching out. Have you had a read of the supplied error docs in your snippet above? If that means something to you, that would be a good place to start debugging.
Alternatively, for me to accurately identify the issue here, I'll need a simplified reproduction that I can run locally. If you could put together a repo that isolates the issue that would be great.
One thing I can say on the above, your <script>
tag is missing a closing brace. Whether this is just a copy/paste error, or present in your integration, only you can say :)
For example:
<script src="https://cdn.jsdelivr.net/npm/@minimal-analytics/ga4/dist/index.js" async</script>
Notice after async
.
Aside from that, please let me know when you have something runnable / shareable, and I can take a closer look.
All the best 👍
I forgot to paste the closing brace, but with a closing brace I get the same error. I don't know much about javascript, but I have also tested the minimal GA4 script from Dariusz and that script was working well. The main disadvantage of that script is that conversions are not tracked, although page_location is tracked and the conversion goal is based on page_location.
Is it possible to track conversions in GA4 with your script (with a conversion goal based on page_location)? If yes, then it's worth putting in the time. Is it possible to integrate your script like the script from Dariusz? The difference is that Dariusz added the tracking ID in the script, so that I only have to add the script src line. I think that can solve the error.
Yes, you'll be able to track conversions based on page location, path, etc. You can also manually track conversion via custom events, if needed.
The distributable is provided in the umd
format, so it supports require.js
. My hunch is Magento is using this same module loader pattern, and isn't playing nicely together.
To better help, I'll need:
Let me know when you have the above and we'll take it from there 👍
I can give you access to a Magento test shop. Is that okay? For this I need an email address to which I can send the login details. I also need your IP address, because the test shop is blocked for other visitors.
Reproducing the issue in a Magento test shop is quite simple, because you only have to add the script in the admin: Content -> Design Configuration -> Store -> HTML Head - Scripts and Styles Sheets
Thanks @Jeroen999, that would give me something to work with.
Before you do so, could you copy the actual code that's being included on the page, e.g from the document? I notice you're using the Admin UI to do so, which might be modifying the script in some way.
I checked the script in the document. The only difference is that the second part has been minified:
Hmm, ok thanks. Do you have a public url I can take a look at?
It is not a public url, but I can make the url visible for you if you send your IP address.
OK great, can you DM me on Twitter (I don't know if Github has an equivalent, and I don't really want to publicly post): https://twitter.com/jahilldev
I see on Twitter that I can't send a message to you. My Twitter username is: @jg_9
Sorry, DM now open
I can now select your username, but I get the error that the message can not be sent. If you don't mind sharing your email address with me, then you can send your email address to the email address of my webshop: klantenservice@shopcore.nl
Hey @Jeroen999, apologies on the delay, I'm unable to find time to look at this right now, I'll try and get back to it later in the week 👍
Okay. There's no rush for me.
You can see the minimal GA4 script in my German shop: https://www.shopcore.de
I have searched for solutions for this error on Google. I think "define([],t)" should get a name. If I change this to "define('ga4de',[],t)", then I don't get the error. However, the script doesn't work when I change this because I don't see visits in my Google Analytics account.
I have tested the minimal analytics script for GA4 in a Magento shop with the default installation instruction:
<script src="https://cdn.jsdelivr.net/npm/@minimal-analytics/ga4/dist/index.js" async
I get this error in the browser console:
require.min.js:17 Uncaught Error: Mismatched anonymous define() module: ()=>(()=>{"use strict";var e={508:(e,t,n)=>{function o(e,t=300,n=0){return(...o)=>
.......................
analytics.com/g/collect";navigator.sendBeacon(
${r}?${s}
),k(t),m=!0}e.track=D,r&&(window.track=D),a&&D()})(),o})() https://requirejs.org/docs/errors.html#mismatch at makeError (require.min.js:17:53) at intakeDefines (require.min.js:81:132) at require.min.js:104:45 makeError @ require.min.js:17 intakeDefines @ require.min.js:81 (anonymous) @ require.min.js:104 setTimeout (async)req.nextTick @ require.min.js:123 localRequire @ require.min.js:104 defContext.require @ mixins.min.js:11 requirejs @ require.min.js:123 (anonymous) @ (index):1593