• Resolved Daniella

    (@ellaj)


    Hi,
    Does anyone know how to fix this page error?
    In firebug it says,
    missing } after try block
    pageTracker._trackPageview();\n

    and

    The code looks like:

    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("");
    pageTracker._trackPageview();
    </script>

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Should be this:

    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    Thread Starter Daniella

    (@ellaj)

    Thanks, but where do I put it. The plugin code is as follows:

    /*
    		 * Insert the tracking code into the page
    		 */
    		function spool_analytics() {
    			global $wp_query;
    			$options  = get_option('GoogleAnalyticsPP');
    
    			if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) {
    				echo "\n".'<!-- Google Analytics for WordPress | https://yoast.com/wordpress/google-analytics/ -->'."\n";
    				echo '<script type="text/javascript">'."\n";
    				echo "\t".'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "https://www.");'."\n";
    				echo "\t".'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));'."\n";
    				echo '</script>'."\n";
    				echo '<script type="text/javascript">'."\n";
    				echo "\t".'try {'."\n";
    				echo "\t\t".'var pageTracker = _gat._getTracker("'.$options["uastring"].'");'."\n";
    
    				/**
    				 * If this is a 404 page, track the 404 and prevent all other stuff as it's not needed.
    				 */
    				if ( is_404() ) {
    					echo "\t\t".'pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);'."\n";
    					echo "\t".'} catch(err) {}'."\n";
    					echo '</script>'."\n";
    				} else if ($wp_query->is_search && $wp_query->found_posts == 0) {
    					echo "\t\t".'pageTracker._trackPageview("'.get_bloginfo('url').'/?s=no-results: '.rawurlencode($wp_query->query_vars['s']).'&cat=no-results");'."\n";
    					echo "\t".'} catch(err) {}'."\n";
    					echo '</script>'."\n";
    				} else {
    					if ( $options["extrase"] ) {
    						/**
    						 * We need to load another script, so we need to close the try / catch, load the script, and open it again.
    						 */
    						echo "\t".'} catch(err) {}'."\n";
    						echo '</script>'."\n";
    						echo '<script src="'.gapp_plugin_path().'custom_se.js" type="text/javascript"></script>'."\n";
    						echo '<script type="text/javascript">'."\n";
    						echo "\t".'try {'."\n";
    					}	
    
    					if ( $options['userv2'] )
    						echo "\t\t".'pageTracker._setLocalRemoteServerMode();'."\n";
    
    					if ( $options['allowanchor'] )
    						echo "\t\t".'pageTracker._setAllowAnchor(true);'."\n";
    
    					if ( $options['trackloggedin'] && !isset($_COOKIE['__utmv']) && is_user_logged_in() )
    						echo "\t\tpageTracker._setVar('logged-in');\n";
    					else
    						echo "\t\t// Cookied already: ".$_COOKIE['__utmv']."\n";
    
    					if ( isset($options['domain']) && $options['domain'] != "" ) {
    						if (substr($options['domain'],0,1) != ".")
    							$options['domain'] = ".".$options['domain'];
    						echo "\t\t".'pageTracker._setDomainName("'.$options['domain'].'");'."\n";
    					}
    
    					if ( strpos($_SERVER['HTTP_REFERER'],"images.google") && strpos($_SERVER['HTTP_REFERER'],"&prev") && $options["imagese"] ) {
    						echo "\t\t".'pageTracker._addOrganic("images.google","prev");'."\n";
    						// echo "\t\t".'regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");'."\n";
    						// echo "\t\t".'var match = regex.exec(pageTracker.qa);'."\n";
    						// echo "\t\t".'pageTracker.qa = "https://images.google." + match[1] + unescape(match[2]);'."\n";
    					}
    
    					echo "\t\t".'pageTracker._trackPageview();'."\n";
    					echo "\t".'} catch(err) {}'."\n";
    					echo '</script>'."\n";
    				}
    				echo '<!-- End of Google Analytics code -->'."\n";
    			} else if ( $options["uastring"] != "" && current_user_can('edit_users') && !$options["admintracking"] ) {
    				echo "<!-- Google Analytics tracking code not shown because admin tracking is disabled -->";
    			} else if ( $options["uastring"] == "" && current_user_can('edit_users') ) {
    				echo "<!-- Google Analytics tracking code not shown because yo haven't entered your UA string yet. -->";
    			}
    		}

    Thank you.

    Thread Starter Daniella

    (@ellaj)

    I fixed it. Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Google Analytics missing bracket’ is closed to new replies.