public function render()
    {
        $script[] = $this->_getJavascriptTemplateBlockBegin();

        $trackingUserId = (null === $this->userId)
            ? ''
            : sprintf(", {'userId': '%s'}", $this->userId);

        if ($this->debug) {
            $script[] = "ga('create', '{$this->trackingId}', { 'cookieDomain': 'none' }, '{$this->trackerName}'{$trackingUserId});";
        } else {
            $script[] = "ga('create', '{$this->trackingId}', '{$this->trackingDomain}', '{$this->trackerName}'{$trackingUserId});";
        }

        if ($this->ecommerceTracking) {
            $script[] = "ga('require', 'ecommerce');";
        }

        if ($this->displayFeatures) {
            $script[] = "ga('require', 'displayfeatures');";
        }

        if ($this->anonymizeIp) {
            $script[] = "ga('set', 'anonymizeIp', true);";
        }

        if ($this->nonInteraction) {
            $script[] = "ga('set', 'nonInteraction', true);";
        }

        if ($this->campaign instanceof Campaign) {
            $script[] = (new CampaignRenderer($this->campaign))->render();
        }

        $trackingStack = $this->trackingBag->get();
        if (count($trackingStack)) {
            $script[] = implode("\n", $trackingStack);
        }

        if ($this->autoTrack) {
            $script[] = "ga('send', 'pageview');";
        }

        if ($this->ecommerceTracking) {
            $script[] = "ga('ecommerce:send');";
        }

        $script[] = $this->_getJavascriptTemplateBlockEnd();

        return implode('', $script);
    }