analyticsFileTypes' is undefined Error: EASY FIX
-
Hey guys,
I’ve been bumping up against an error in Google Analyticator lately and have discovered that it’s actually a long-running problem from before you took over. Luckily the solution is simple!
Here’s the js error that comes up in console (and blocks all other js on the page from executing, e.g. admin bar):
Uncaught ReferenceError: analyticsFileTypes is not defined
Here’s a very old thread that ends in both a summary of the current problem and an example solution: https://www.ads-software.com/support/topic/plugin-google-analyticator-analyticsfiletypes-is-undefined?replies=4
It only occurs if you have external link tracking enabled in the Analyticator settings because it is caused by the accidental loading of the external-tracking.min.js file on post previews.
I think the original issue in that thread was fixed by what is now in
add_google_analytics()
on line 967 of google-analyticator.php:if ( !function_exists("is_preview") || ( function_exists("is_preview") && !is_preview() ) )
That runs just before all the main javascript is output, and prevents preview pageloads from being tracked.
The remaining problem, as shown in the old thread, is that the
external-tracking.min.js
file is not enqueued inadd_google_analytics()
, but instead in a separate function,ga_outgoing_links()
. The result is that the external-tracking js gets loaded whenis_preview()
, but because the main JS it depends on isn’t loaded it causes a fatal JS error.The clear solution is to add an
is_preview()
check inga_outgoing_links()
to match the one inadd_google_analytics()
. To me the right place would be line 1068 of google-analyticator.php, where you’re already checkingis_admin()
before enqueuing the script. Clearly the two checks are related, and in this case post previews ARE “admin” insofar as we do not want to track them:So this:
# If this is not an admin page if ( !is_admin() )
becomes:
# If this is not an admin page and not a post being previewed if ( !is_admin() AND !is_preview() )
Thank you for fixing this in the next version, and please let me know if I failed to explain anything well.
- The topic ‘analyticsFileTypes' is undefined Error: EASY FIX’ is closed to new replies.