Skip to content
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

require.min.js:17 Uncaught Error: Mismatched anonymous define() module: #39

Open
Jeroen999 opened this issue Feb 20, 2023 · 15 comments
Open
Labels

Comments

@Jeroen999
Copy link

Jeroen999 commented Feb 20, 2023

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</script> <script> window.minimalAnalytics = { trackingId: 'my tracking ID', autoTrack: true, }; </script>

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

@jahilldev
Copy link
Owner

jahilldev commented Feb 20, 2023

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 👍

@jahilldev jahilldev added the ga4 label Feb 20, 2023
@Jeroen999
Copy link
Author

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.

@jahilldev
Copy link
Owner

jahilldev commented Feb 20, 2023

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:

  • A stripped down (simple!) reproduction highlighting the issue
  • The full error output
  • Exactly how you're integrating the script into your Magento site

Let me know when you have the above and we'll take it from there 👍

@Jeroen999
Copy link
Author

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

@jahilldev
Copy link
Owner

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.

@Jeroen999
Copy link
Author

I checked the script in the document. The only difference is that the second part has been minified:

<script>window.minimalAnalytics={trackingId:'MY_TRACKING_ID',autoTrack:true,};</script>

@jahilldev
Copy link
Owner

Hmm, ok thanks. Do you have a public url I can take a look at?

@Jeroen999
Copy link
Author

It is not a public url, but I can make the url visible for you if you send your IP address.

@jahilldev
Copy link
Owner

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

@Jeroen999
Copy link
Author

I see on Twitter that I can't send a message to you. My Twitter username is: @jg_9

@jahilldev
Copy link
Owner

Sorry, DM now open

@Jeroen999
Copy link
Author

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: [email protected]

@jahilldev
Copy link
Owner

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 👍

@Jeroen999
Copy link
Author

Okay. There's no rush for me.

@Jeroen999
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants