config = $config; $this->serializer = $serializer; } /** * Render GTM tracking scripts * * @return string */ protected function _toHtml() { if (! $this->config->isGtmEnabled()) { return ''; } return parent::_toHtml(); } /** * Return cookie restriction mode value. * * @return string */ public function getGtmContainerId(): string { return $this->config->getGtmContainerId(); } /** * @return string */ public function getGtmServerBaseUrl(): string { return $this->config->getGtmServerBaseUrl(); } /** * Return cookie restriction mode value. * * @return string */ public function getGmtAssociatedCategoryKey(): string { return $this->config->getGmtAssociatedCategoryKey(); } /** * Check if consent mode enabled * * @return int */ public function isConsentModeEnabled(): int { return (int) $this->config->isGtmConsentModeEnabled(); } /** * Retrieve consent types default status * * @return string */ public function getDefaultConsentTypesStatus(): string { $result = []; if ($this->isConsentModeEnabled()) { foreach ($this->config->getGtmConsentTypesConfig() as $config) { $result[$config['consent_type']] = $config['status']; } } return $this->serializer->serialize($result); } /** * Retrieve consent types default status * * @return array */ public function getDefaultConsentStatus(): array { $result = []; if ($this->isConsentModeEnabled()) { foreach ($this->config->getGtmConsentTypesConfig() as $config) { $result[$config['consent_type']] = $config['status']; } } return $result; } /** * Retrieve cookie categories assigned to the consent types * * @return string */ public function getConsentTypesCategories(): string { $result = []; if ($this->isConsentModeEnabled()) { foreach ($this->config->getGtmConsentTypesConfig() as $config) { $result[$config['consent_type']] = $config['cookie_category']; } } return $this->serializer->serialize($result); } /** * Get cookie categories to consent types mapping. * * @return array */ public function getCategoriesMapping(): array { $result = []; if ($this->isConsentModeEnabled()) { foreach ($this->config->getGtmConsentTypesConfig() as $config) { $result[$config['consent_type']] = $config['cookie_category']; } } return $result; } /** * Get serialized config. * * @return string */ public function getJsonConfig(): string { return $this->serializer->serialize([ 'categoryKey' => $this->getGmtAssociatedCategoryKey(), 'containerId' => $this->getGtmContainerId(), 'consentMode' => $this->isConsentModeEnabled(), 'defaultConsentTypes' => $this->getDefaultConsentStatus(), 'consentTypesCategories' => $this->getCategoriesMapping() ]); } }