• 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: http://wordpress.org/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 in add_google_analytics(), but instead in a separate function, ga_outgoing_links(). The result is that the external-tracking js gets loaded when is_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 in ga_outgoing_links() to match the one in add_google_analytics(). To me the right place would be line 1068 of google-analyticator.php, where you’re already checking is_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.

    http://wordpress.org/plugins/google-analyticator/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jer Clarke

    (@jeremyclarke)

    UPDATE: Hey guys sorry for the noise, but I just realized that the solution above shouldn’t actually fix the problem (though strangely it stopped the browser error for me which is why I thought it was working).

    It seems that the ga_outgoing_links(), when run on the ‘init’ hook doesn’t have proper access to is_preview() and returns false even when it IS a preview.

    It DOES work in ga_external_tracking_js() though (‘wp_print_scripts’ hook), so exiting that function if (is_preview()) does the trick. Here’s the full function with the preview check (starting at line 1080):

    /**
     * Adds the scripts required for outbound link tracking
     **/
    function ga_external_tracking_js()
    {
    	// Exit if this is a post preview
    	if (is_preview())
    		return;
    
    	$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    	wp_enqueue_script('ga-external-tracking', plugins_url("/google-analyticator/external-tracking{$suffix}.js"), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
    }

    Thanks!

    Thread Starter Jer Clarke

    (@jeremyclarke)

    Guys, any movement on this? It’s a small edit and you’ve had releases since I posted this.

    Thanks.

    Given that this topic is 6 months old, I would suggest that you post a new topic on this subject – referencing this topic as background info if needed.

    Thread Starter Jer Clarke

    (@jeremyclarke)

    Esmi I respect your position but the dates on this topic are part of it’s content and meaning. I don’t think duplicating the content of this thread would be good for the forum. Usually the Analyticator devs respond to stuff like this so I think they just fell behind.

    Hi Jeremy,

    You are correct this did slip through the cracks.

    We will make this update, and as mentioned before in the previous question about the API key, it would be great if you could test this fix as well (the more testers the better!)

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘analyticsFileTypes' is undefined Error: EASY FIX’ is closed to new replies.