diff --git a/app/Module/YandexMetrica.php b/app/Module/YandexMetrica.php new file mode 100644 index 00000000000..7d9bece253d --- /dev/null +++ b/app/Module/YandexMetrica.php @@ -0,0 +1,122 @@ +. + */ + +declare(strict_types=1); + +namespace Fisharebest\Webtrees\Module; + +use Fisharebest\Webtrees\I18N; + +/** + * Class YandexMetrica - add support for Yandex Metrica. + */ +class YandexMetrica extends AbstractModule implements ModuleAnalyticsInterface, ModuleConfigInterface, ModuleExternalUrlInterface, ModuleGlobalInterface +{ + use ModuleAnalyticsTrait; + use ModuleConfigTrait; + use ModuleExternalUrlTrait; + use ModuleGlobalTrait; + + /** + * How should this module be identified in the control panel, etc.? + * + * @return string + */ + public function title(): string + { + return I18N::translate('Yandex Metrica'); + } + + /** + * Should this module be enabled when it is first installed? + * + * @return bool + */ + public function isEnabledByDefault(): bool + { + return false; + } + + /** + * Is this a tracker, as opposed to just a site-verification. + * + * @return bool + */ + public function isTracker(): bool + { + return false; + } + + /** + * Form fields to edit the parameters. + * + * @return string + */ + public function analyticsFormFields(): string + { + return view('modules/yandex-metrica/form', $this->analyticsParameters()); + } + + /** + * Home page for the service. + * + * @return string + */ + public function externalUrl(): string + { + return 'https://metrika.yandex.ru'; + } + + /** + * The parameters that need to be embedded in the snippet. + * + * @return array + */ + public function analyticsParameters(): array + { + return [ + 'YANDEX_METRICA_ID' => $this->getPreference('YANDEX_METRICA_ID') + ]; + } + + /** + * Embed placeholders in the snippet. + * + * @param array $parameters + * + * @return string + */ + public function analyticsSnippet(array $parameters): string + { + return view('modules/yandex-metrica/snippet', $parameters); + } + + /** + * Raw content, to be added at the end of the element. + * Typically, this will be and elements. + * + * @return string + */ + public function headContent(): string + { + if ($this->analyticsCanShow()) { + return $this->analyticsSnippet($this->analyticsParameters()); + } + + return ''; + } +} diff --git a/app/Services/ModuleService.php b/app/Services/ModuleService.php index da7a31f5c56..02875ea8659 100644 --- a/app/Services/ModuleService.php +++ b/app/Services/ModuleService.php @@ -255,6 +255,7 @@ use Fisharebest\Webtrees\Module\WelcomeBlockModule; use Fisharebest\Webtrees\Module\XeneaTheme; use Fisharebest\Webtrees\Module\YahrzeitModule; +use Fisharebest\Webtrees\Module\YandexMetrica; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Tree; use Fisharebest\Webtrees\Webtrees; @@ -380,6 +381,7 @@ class ModuleService 'google-analytics' => GoogleAnalyticsModule::class, 'google-maps' => GoogleMaps::class, 'google-webmaster-tools' => GoogleWebmasterToolsModule::class, + 'yandex-metrica' => YandexMetrica::class, 'here-maps' => HereMaps::class, 'hit-counter' => HitCountFooterModule::class, 'hourglass_chart' => HourglassChartModule::class, diff --git a/resources/views/modules/yandex-metrica/form.phtml b/resources/views/modules/yandex-metrica/form.phtml new file mode 100644 index 00000000000..20c88429b16 --- /dev/null +++ b/resources/views/modules/yandex-metrica/form.phtml @@ -0,0 +1,21 @@ + + +
+ +
+ +
+
+ +

+ +

diff --git a/resources/views/modules/yandex-metrica/snippet.phtml b/resources/views/modules/yandex-metrica/snippet.phtml new file mode 100644 index 00000000000..170e46d1622 --- /dev/null +++ b/resources/views/modules/yandex-metrica/snippet.phtml @@ -0,0 +1,25 @@ + + + + + diff --git a/tests/app/Module/YandexMetricaTest.php b/tests/app/Module/YandexMetricaTest.php new file mode 100644 index 00000000000..4f0e9eb12b2 --- /dev/null +++ b/tests/app/Module/YandexMetricaTest.php @@ -0,0 +1,35 @@ +. + */ + +declare(strict_types=1); + +namespace Fisharebest\Webtrees\Module; + +use Fisharebest\Webtrees\TestCase; + +/** + * Test harness for the class YandexMetrica + * + * @covers Fisharebest\Webtrees\Module\YandexMetrica + */ +class YandexMetricaTest extends TestCase +{ + public function testClass(): void + { + $this->assertTrue(class_exists(\Fisharebest\Webtrees\Module\YandexMetrica::class)); + } +}