kartik\social\GoogleAnalytics::init PHP Method

init() public method

Initialize the widget
public init ( )
    public function init()
    {
        $this->validPlugins = false;
        parent::init();
        $this->setConfig('googleAnalytics');
        if (empty($this->id)) {
            throw new InvalidConfigException("Google analytics tracking 'id' has not been set.");
        }
        if (empty($this->domain)) {
            throw new InvalidConfigException("Google analytics tracking 'domain' has not been set.");
        }
        if ($this->anonymizeIp === self::HIT_ALL) {
            $this->jsBeforeSend .= "{$this->objectName}('set', 'anonymizeIp', true);\n";
        } elseif ($this->anonymizeIp === self::HIT_EACH && !is_string($this->sendConfig)) {
            $this->sendConfig['anonymizeIp'] = true;
        }
        if ($this->testMode === true && !is_string($this->trackerConfig)) {
            $this->trackerConfig['cookieDomain'] = 'none';
        }
        $trackerConfig = empty($this->trackerConfig) ? '' : ', ' . (is_array($this->trackerConfig) ? Json::encode($this->trackerConfig) : $this->trackerConfig);
        $sendConfig = empty($this->sendConfig) ? '' : ', ' . (is_array($this->sendConfig) ? Json::encode($this->sendConfig) : $this->sendConfig);
        $params = ['id' => $this->id, 'domain' => $this->domain, 'anonIp' => $this->anonymizeIp, 'obj' => $this->objectName, 'trackerConfig' => $trackerConfig, 'sendConfig' => $sendConfig, 'jsBeforeSend' => $this->jsBeforeSend, 'jsAfterSend' => $this->jsAfterSend, 'noscript' => $this->renderNoScript()];
        echo $this->render('google-analytics', $params);
    }
GoogleAnalytics