algolia / search-insights-gtm

Google Tag Manager template for detecting front-end Algolia search metrics
Apache License 2.0
6 stars 5 forks source link

fix: use iife in case requirejs is included in customers' website #12

Closed eunjae-lee closed 2 years ago

eunjae-lee commented 2 years ago

Summary

This PR selectively loads iife version of search-insights in case requirejs is included in customers' website, because requirejs clashes with umd version of search-insights (ref: https://github.com/algolia/search-insights.js/pull/274)

Especially, we've seen requirejs being used in Magento 2. The url of search-insights is hard-coded in the template. If we don't provide this, user will have to modify the template by themselves which will make a fork, thus they won't get update in the future.

eunjae-lee commented 2 years ago

Do we have a reproduction of the issue in a codesandbox somewhere?

Unfortunately it's not trivial to have a test environment for GTM. (I'm doing a test with a test app running locally + GTM, though)

For a short version:

https://codesandbox.io/s/elated-lalande-elvc7?file=/index.html:244-449

If you run it there's a requirejs + search-insights (UMD). You can see the error in the console.

And if you append /dist/search-insights.iife.min.js to the URL, then it works fine. (try window.aa)

eunjae-lee commented 2 years ago

Well, actually testing this locally, I've found something weird. I'll ping you later for review.