Commits

Sam Stenvall committed fde5f25

split the Javascript snippet into two parts which can be registered at different
positions

Comments (0)

Files changed (1)

components/GoogleAnalytics.php

 		if (!isset($this->accountId))
 			return;
 
-		$script = <<<EOD
+		$headScript = <<<EOD
 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', '{$this->accountId}']);
 _gaq.push(['_trackPageview']);
+EOD;
 
-{$this->getTransactionsJS()}
+		$bodyEndScript = $this->getTransactionsJS();
+		$bodyEndScript .= <<<EOD
 
 (function() {
 	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 })();
 EOD;
 
-		Yii::app()->clientScript->registerScript(__CLASS__.'#tracking', $script, CClientScript::POS_HEAD);
+		Yii::app()->clientScript->registerScript(__CLASS__.'#tracking-head', $headScript, CClientScript::POS_HEAD);
+		Yii::app()->clientScript->registerScript(__CLASS__.'#tracking-body', $bodyEndScript, CClientScript::POS_END);
 	}
 
 	/**