src/Kunstmaan/SeoBundle/Twig/GoogleAnalyticsTwigExtension.php
public function renderInitialize(\Twig_Environment $environment, $options = null)
    {
        if (is_null($options)) {
            $options = array();
        }

        $defaults = array();

        $this->setOptionIfNotSet($defaults, $this->accountVarName, $this->accountId);

        // Things set in $options will override things set in $defaults.
        $options = array_merge($defaults, $options);

        if (!$this->isOptionSet($options, $this->accountVarName)) {
            throw new \Twig_Error_Runtime(
                "The google_analytics_initialize function depends on a Google Analytics account ID. You can either pass this along in the initialize_google_analytics function ($this->accountVarName), provide a variable under 'parameters.google.analytics.account_id'."
            );
        }

        $template = $environment->loadTemplate('KunstmaanSeoBundle:GoogleAnalyticsTwigExtension:init.html.twig');

        return $template->render($options);
    }
public function renderInitialize(\Twig_Environment $environment, $options = null)
    {
        if (is_null($options)) {
            $options = array();
        }

        $defaults = array();

        $this->setOptionIfNotSet($defaults, $this->accountVarName, $this->accountId);

        // Things set in $options will override things set in $defaults.
        $options = array_merge($defaults, $options);

        if (!$this->isOptionSet($options, $this->accountVarName)) {
            throw new \Twig_Error_Runtime(
                "The google_analytics_initialize function depends on a Google Analytics account ID. You can either pass this along in the initialize_google_analytics function ($this->accountVarName), provide a variable under 'parameters.google.analytics.account_id'."
            );
        }

        $template = $environment->loadTemplate('KunstmaanSeoBundle:GoogleAnalyticsTwigExtension:init.html.twig');

        return $template->render($options);
    }
public function renderInitialize ( \ Twig_Environment $ environment , $ options = null ) { if ( is_null ( $ options ) ) { $ options = array ( ) ; } $ defaults = array ( ) ; $ this -> setOptionIfNotSet ( $ defaults , $ this -> accountVarName , $ this -> accountId ) ; // Things set in $options will override things set in $defaults. $ options = array_merge ( $ defaults , $ options ) ; if ( ! $ this -> isOptionSet ( $ options , $ this -> accountVarName ) ) { throw new \ Twig_Error_Runtime ( "The google_analytics_initialize function depends on a Google Analytics account ID. You can either pass this along in the initialize_google_analytics function ($this->accountVarName), provide a variable under 'parameters.google.analytics.account_id'." ) ; } $ template = $ environment -> loadTemplate ( 'KunstmaanSeoBundle:GoogleAnalyticsTwigExtension:init.html.twig' ) ; return $ template -> render ( $ options ) ; }
Renders the default Google Analytics JavaScript.

If the options are not set it'll try and load the account ID from your parameters (google.analytics.account_id)

@param $environment \Twig_Environment
@param $options     array|null        Example: {account_id: 'UA-XXXXX-Y'}

@return string the HTML rendered

@throws \Twig_Error_Runtime when the Google Analytics ID is nowhere to be found
Renders the default Google Analytics JavaScript .