/** * returns the javascript embedding code * * @return string */ public function render() { $script[] = $this->_getJavascriptTemplateBlockBegin(); $trackingUserId = null === $this->userId ? '' : sprintf(", {'userId': '%s'}", $this->userId); if ($this->debug || App::environment('local')) { $script[] = "ga('create', '{$this->trackingId}', { 'cookieDomain': 'none' }{$trackingUserId});"; } else { $script[] = "ga('create', '{$this->trackingId}', '{$this->trackingDomain}'{$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); }