From d60518ca77d01adc71f7124146222eca4ec48ef5 Mon Sep 17 00:00:00 2001 From: Alexander <81816278+azlydnev@users.noreply.github.com> Date: Sun, 15 Oct 2023 14:50:16 +0300 Subject: [PATCH 1/7] Create YandexMetrica.php --- app/Module/YandexMetrica.php | 122 +++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 app/Module/YandexMetrica.php diff --git a/app/Module/YandexMetrica.php b/app/Module/YandexMetrica.php new file mode 100644 index 00000000000..bd13506e99b --- /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-webmaster-tools/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-webmaster-tools/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 ''; + } +} From ae983e0c6a065c782f0be04c10eeddc8e51e0951 Mon Sep 17 00:00:00 2001 From: Alexander <81816278+azlydnev@users.noreply.github.com> Date: Sun, 15 Oct 2023 14:53:03 +0300 Subject: [PATCH 2/7] Create form.phtml --- .../views/modules/yandex-metrica/form.phtml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 resources/views/modules/yandex-metrica/form.phtml 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 @@ + + +
+ +
+ +
+
+ +

+ +

From 49f344856eb44789238be4963f6df51b7548085f Mon Sep 17 00:00:00 2001 From: Alexander <81816278+azlydnev@users.noreply.github.com> Date: Sun, 15 Oct 2023 14:54:53 +0300 Subject: [PATCH 3/7] Create snippet.phtml --- .../modules/yandex-metrica/snippet.phtml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 resources/views/modules/yandex-metrica/snippet.phtml 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 @@ + + + + + From 63ef5957dd197efdfa229789ef43927b24a8cc3f Mon Sep 17 00:00:00 2001 From: Alexander <81816278+azlydnev@users.noreply.github.com> Date: Sun, 15 Oct 2023 14:56:42 +0300 Subject: [PATCH 4/7] Update YandexMetrica.php --- app/Module/YandexMetrica.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Module/YandexMetrica.php b/app/Module/YandexMetrica.php index bd13506e99b..7d9bece253d 100644 --- a/app/Module/YandexMetrica.php +++ b/app/Module/YandexMetrica.php @@ -68,7 +68,7 @@ public function isTracker(): bool */ public function analyticsFormFields(): string { - return view('modules/yandex-webmaster-tools/form', $this->analyticsParameters()); + return view('modules/yandex-metrica/form', $this->analyticsParameters()); } /** @@ -102,7 +102,7 @@ public function analyticsParameters(): array */ public function analyticsSnippet(array $parameters): string { - return view('modules/yandex-webmaster-tools/snippet', $parameters); + return view('modules/yandex-metrica/snippet', $parameters); } /** From ac88afba2bd98f7c9f1ff7ce0905e1eb0dd3ba4a Mon Sep 17 00:00:00 2001 From: Alexander <81816278+azlydnev@users.noreply.github.com> Date: Sun, 15 Oct 2023 15:04:18 +0300 Subject: [PATCH 5/7] Create YandexMetricaTest.php --- tests/app/Module/YandexMetricaTest.php | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/app/Module/YandexMetricaTest.php diff --git a/tests/app/Module/YandexMetricaTest.php b/tests/app/Module/YandexMetricaTest.php new file mode 100644 index 00000000000..6f738ba515c --- /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 GoogleWebmasterToolsModule + * + * @covers Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule + */ +class GoogleWebmasterToolsModuleTest extends TestCase +{ + public function testClass(): void + { + $this->assertTrue(class_exists(\Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule::class)); + } +} From e69a9c3abb5b29a4c4995090c0459c512c7b4f60 Mon Sep 17 00:00:00 2001 From: Alexander <81816278+azlydnev@users.noreply.github.com> Date: Sun, 15 Oct 2023 15:09:59 +0300 Subject: [PATCH 6/7] Update ModuleService.php --- app/Services/ModuleService.php | 2 ++ 1 file changed, 2 insertions(+) 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, From 45781495fb26d974af612ca7f36fd8cfa3dedf24 Mon Sep 17 00:00:00 2001 From: Alexander <81816278+azlydnev@users.noreply.github.com> Date: Sun, 15 Oct 2023 15:16:42 +0300 Subject: [PATCH 7/7] Update YandexMetricaTest.php --- tests/app/Module/YandexMetricaTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/app/Module/YandexMetricaTest.php b/tests/app/Module/YandexMetricaTest.php index 6f738ba515c..4f0e9eb12b2 100644 --- a/tests/app/Module/YandexMetricaTest.php +++ b/tests/app/Module/YandexMetricaTest.php @@ -22,14 +22,14 @@ use Fisharebest\Webtrees\TestCase; /** - * Test harness for the class GoogleWebmasterToolsModule + * Test harness for the class YandexMetrica * - * @covers Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule + * @covers Fisharebest\Webtrees\Module\YandexMetrica */ -class GoogleWebmasterToolsModuleTest extends TestCase +class YandexMetricaTest extends TestCase { public function testClass(): void { - $this->assertTrue(class_exists(\Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule::class)); + $this->assertTrue(class_exists(\Fisharebest\Webtrees\Module\YandexMetrica::class)); } }