-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yandex Metrica counter snippet #4895
Open
azlydnev
wants to merge
8
commits into
fisharebest:main
Choose a base branch
from
azlydnev:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d60518c
Create YandexMetrica.php
azlydnev ae983e0
Create form.phtml
azlydnev 49f3448
Create snippet.phtml
azlydnev 63ef595
Update YandexMetrica.php
azlydnev ac88afb
Create YandexMetricaTest.php
azlydnev e69a9c3
Update ModuleService.php
azlydnev 4578149
Update YandexMetricaTest.php
azlydnev 444e439
Merge pull request #1 from azlydnev/azlydnev-yandex-metrica
azlydnev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
/** | ||
* webtrees: online genealogy | ||
* Copyright (C) 2023 webtrees development team | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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<string> | ||
*/ | ||
public function analyticsParameters(): array | ||
{ | ||
return [ | ||
'YANDEX_METRICA_ID' => $this->getPreference('YANDEX_METRICA_ID') | ||
]; | ||
} | ||
|
||
/** | ||
* Embed placeholders in the snippet. | ||
* | ||
* @param array<string> $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 <head> element. | ||
* Typically, this will be <link> and <meta> elements. | ||
* | ||
* @return string | ||
*/ | ||
public function headContent(): string | ||
{ | ||
if ($this->analyticsCanShow()) { | ||
return $this->analyticsSnippet($this->analyticsParameters()); | ||
} | ||
|
||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Fisharebest\Webtrees\I18N; | ||
|
||
?> | ||
|
||
<div class="row mb-3"> | ||
<label for="YANDEX_METRICA_ID" class="col-sm-3 col-form-label"> | ||
<?= /* I18N: A configuration setting */ I18N::translate('Yandex Metica') ?> | ||
<span class="visually-hidden">Yandex Metrica</span> | ||
</label> | ||
<div class="col-sm-9"> | ||
<input type="text" class="form-control" id="YANDEX_METRICA_ID" name="YANDEX_METRICA_ID" value="<?= e($YANDEX_METRICA_ID ?? '') ?>" maxlength="255" pattern="[0-9]+"> | ||
</div> | ||
</div> | ||
|
||
<p> | ||
<?= I18N::translate('Yandex Metrica') ?> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @var string $YANDEX_METICA_ID, | ||
*/ | ||
?> | ||
<!-- Yandex.Metrika counter --> | ||
<script type="text/javascript" > | ||
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; | ||
m[i].l=1*new Date(); | ||
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }} | ||
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) | ||
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"); | ||
|
||
ym(<?= json_encode((int) ($YANDEX_METRICA_ID ?? ''), JSON_THROW_ON_ERROR) ?> , "init", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are casting this value to an Also, |
||
clickmap:true, | ||
trackLinks:true, | ||
accurateTrackBounce:true, | ||
webvisor:true | ||
}); | ||
</script> | ||
<noscript><div><img src="https://mc.yandex.ru/watch/<?= e($YANDEX_METRICA_ID ?? '') ?>" style="position:absolute; left:-9999px;" alt="" /></div></noscript> | ||
<!-- /Yandex.Metrika counter --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* webtrees: online genealogy | ||
* Copyright (C) 2023 webtrees development team | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Metica -> Metrica