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

All versions of calx.js seem to be breaking Google Analytics 4 and causing all the javascript to fail. #68

Open
martindefatte opened this issue Jan 14, 2023 · 2 comments

Comments

@martindefatte
Copy link

All versions of calx.js seem to be breaking Google Analytics 4 and causing all the javascript to fail.

I've tried using v 1.1.9, 2.0.0 and 2.2.6 and they all seem to cause errors with the new Google Analytics 4. When the legacy analytics becomes deprecated in June of 2023, I'll have to make the decision to not collect analytics or not use the calc plugin. They both seem valuable in different ways.

@Radvansk
Copy link

Radvansk commented Feb 23, 2023

I ran into the same problem and my solution is below. Hope this helps.

  • https://github.com/xsanisty/calx.js/blob/main/jquery-calx-2.2.8.js

  • Line 37 has an issue: if (typeof Array.indexOf !== "function") {

  • The left side of the argument returns undefined. At least it returns undefined at the point where the file was loaded in my pages. Executing this typeof Array.indexOf from the dev tools browser console does return "function" so my assumption is the file was loading before the brower's native indexOf function was there. The plugin is setting the prototype.indexOf for browsers that do not need it which causes the error in gtag.js

  • Change Line 37 to if (!Array.prototype.indexOf) {

  • All done. Now the plugin only sets prototype.indexOf for browsers that actually need it. Which aren't very many and old ones like IE8 that nobody should be concerned about. I'm pretty sure gtag.js won't work in browsers that would access the code in this if block anyway.

@martindefatte
Copy link
Author

Thank you so much! This did the trick. I actually did it on the v1.x version of the plugin as well - been using this before 2.0 came along and I haven't converted the particular site over. MUCH APPRECIATED

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

No branches or pull requests

2 participants