<?php class Analytics_PageTool extends PageTool {
/**
 * Google Analytics.
 * This simple PageTool doesn't have any functionality in the go() method.
 * Instead, pass the tracking code into the track() method.
 */
public function go($api, $dom, $template, $tool) { }

/**
 * Injects the required JavaScript code where needed to start tracking using
 * Google Analytics.
 *
 * @param string $trackingCode Your Google Analytics account code, looks like 
 * this: UA-12345678-1
 */
public function track($trackingCode) {
	$js = file_get_contents(dirname(__FILE__) . "/Include/Analytics.tool.js");
	if($js === false) {
		throw new HttpError(500, "Google Analytics script failure");
	}
	$js = str_replace("{ANALYTICS_CODE}", $trackingCode, $js);
	$this->_dom["head"]->append(
		"script", 
		["data-PageTool" => "Analytics"], 
		$js
	);
}

}#
<?php class Analytics_PageTool extends PageTool {
/**
 * Google Analytics.
 * This simple PageTool doesn't have any functionality in the go() method.
 * Instead, pass the tracking code into the track() method.
 */
public function go($api, $dom, $template, $tool) { }

/**
 * Injects the required JavaScript code where needed to start tracking using
 * Google Analytics.
 *
 * @param string $trackingCode Your Google Analytics account code, looks like 
 * this: UA-12345678-1
 */
public function track($trackingCode) {
	$js = file_get_contents(dirname(__FILE__) . "/Include/Analytics.tool.js");
	if($js === false) {
		throw new HttpError(500, "Google Analytics script failure");
	}
	$js = str_replace("{ANALYTICS_CODE}", $trackingCode, $js);
	$this->_dom["head"]->prependChild(
		"script", 
		["data-PageTool" => "Analytics"], 
		$js
	);
}

}#
Prepend js, improving load times
Prepend js, improving load times
