public function init()
	{
	    $sapi = php_sapi_name();
        if($sapi == 'cli')
            return;

		// Set the alias path
		if (Yii::getPathOfAlias('analytics') === false)
            Yii::setPathOfAlias('analytics', realpath(dirname(__FILE__) . '/..'));

        parent::init();

		// Don't load up the analytics.js if we don't have any data
		$providers = $this->getProviders();
		if (empty($providers))
			return;

		// Conver options into json
		$json = CJSON::encode($providers);

		// Load up the asset manager
		$asset = Yii::app()->assetManager->publish(__DIR__.DS.'assets'.DS.'js', true, -1, YII_DEBUG);
		$cs    = Yii::app()->getClientScript();

		// Register the appropriate script file
		$cs->registerScriptFile($asset . (YII_DEBUG ? '/analytics.js' : '/analytics.min.js'));

		// Initialize
		$cs->registerScript('analytics.js', "analytics.initialize({$json}); analytics.page();");

		if ($this->lowerBounceRate)
		{
			$cs->registerScript('analytics.js-bounce-rate-15', 'setTimeout(function() { analytics.track("_trackEvent", "15 Seconds"); }, 15000 );');
			$cs->registerScript('analytics.js-bounce-rate-30', 'setTimeout(function() { analytics.track("_trackEvent", "30 Seconds"); }, 30000 );');
			$cs->registerScript('analytics.js-bounce-rate-60', 'setTimeout(function() { analytics.track("_trackEvent", "60 Seconds"); }, 60000 );');
		}

	}
public function init()
	{
	    $sapi = php_sapi_name();
        if($sapi == 'cli')
            return;

		// Set the alias path
		if (Yii::getPathOfAlias('analytics') === false)
            Yii::setPathOfAlias('analytics', realpath(dirname(__FILE__) . '/..'));

        parent::init();

		// Don't load up the analytics.js if we don't have any data
		$providers = $this->getProviders();
		if (empty($providers))
			return;

		// Conver options into json
		$json = CJSON::encode($providers);

		// Load up the asset manager
		$asset = Yii::app()->assetManager->publish(__DIR__.DS.'assets'.DS.'js', true, -1, YII_DEBUG);
		$cs    = Yii::app()->getClientScript();

		// Register the appropriate script file
		$cs->registerScriptFile($asset . (YII_DEBUG ? '/analytics.js' : '/analytics.min.js'));

		// Initialize
		$cs->registerScript('analytics.js', "analytics.initialize({$json}); analytics.page();");

		if ($this->lowerBounceRate)
		{
			$cs->registerScript('analytics.js-bounce-rate-15', 'setTimeout(function() { analytics.track("_trackEvent", "15 Seconds"); }, 15000 );');
			$cs->registerScript('analytics.js-bounce-rate-30', 'setTimeout(function() { analytics.track("_trackEvent", "30 Seconds"); }, 30000 );');
			$cs->registerScript('analytics.js-bounce-rate-60', 'setTimeout(function() { analytics.track("_trackEvent", "60 Seconds"); }, 60000 );');
		}

	}
public function init ( ) { $ sapi = php_sapi_name ( ) ; if ( $ sapi == 'cli' ) return ; // Set the alias path if ( Yii :: getPathOfAlias ( 'analytics' ) === false ) Yii :: setPathOfAlias ( 'analytics' , realpath ( dirname ( __FILE__ ) . '/..' ) ) ; parent :: init ( ) ; // Don't load up the analytics.js if we don't have any data $ providers = $ this -> getProviders ( ) ; if ( empty ( $ providers ) ) return ; // Conver options into json $ json = CJSON :: encode ( $ providers ) ; // Load up the asset manager $ asset = Yii :: app ( ) -> assetManager -> publish ( __DIR__ . DS . 'assets' . DS . 'js' , true , - 1 , YII_DEBUG ) ; $ cs = Yii :: app ( ) -> getClientScript ( ) ; // Register the appropriate script file $ cs -> registerScriptFile ( $ asset . ( YII_DEBUG ? '/analytics.js' : '/analytics.min.js' ) ) ; // Initialize $ cs -> registerScript ( 'analytics.js' , "analytics.initialize({$json}); analytics.page();" ) ; if ( $ this -> lowerBounceRate ) { $ cs -> registerScript ( 'analytics.js-bounce-rate-15' , 'setTimeout(function() { analytics.track("_trackEvent", "15 Seconds"); }, 15000 );' ) ; $ cs -> registerScript ( 'analytics.js-bounce-rate-30' , 'setTimeout(function() { analytics.track("_trackEvent", "30 Seconds"); }, 30000 );' ) ; $ cs -> registerScript ( 'analytics.js-bounce-rate-60' , 'setTimeout(function() { analytics.track("_trackEvent", "60 Seconds"); }, 60000 );' ) ; } }
Registers Analytics.js and initializes the tracking code
Registers Analytics . js and initializes the tracking code