支持Google analysis、Microsoft Clarify集成

This commit is contained in:
Chenx221 2024-04-01 14:26:47 +08:00
parent e166bb2991
commit b0cc9c6400
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
3 changed files with 88 additions and 4 deletions

View File

@ -29,6 +29,34 @@ $this->registerCssFile('@web/css/fuckyou-navpadding.css');
<head> <head>
<title><?= Html::encode($this->title).' | '.Yii::$app->name ?></title> <title><?= Html::encode($this->title).' | '.Yii::$app->name ?></title>
<?php $this->head() ?> <?php $this->head() ?>
<?php
if ($_ENV['CLARITY_ENABLED'] === 'true') {
$clarityId = $_ENV['CLARITY_ID'];
echo <<<EOL
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "$clarityId");
</script>
EOL;
}
if ($_ENV['GA_ENABLED'] === 'true') {
$gaId = $_ENV['GA_ID'];
echo <<<EOL
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=$gaId"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '$gaId');
</script>
EOL;
}
?>
</head> </head>
<body class="d-flex flex-column h-100"> <body class="d-flex flex-column h-100">
<?php $this->beginBody() ?> <?php $this->beginBody() ?>

View File

@ -26,6 +26,34 @@ $this->registerLinkTag(['rel' => 'icon', 'type' => 'image/x-icon', 'href' => Yii
<head> <head>
<title><?= Html::encode($this->title).' | '.Yii::$app->name ?></title> <title><?= Html::encode($this->title).' | '.Yii::$app->name ?></title>
<?php $this->head() ?> <?php $this->head() ?>
<?php
if ($_ENV['CLARITY_ENABLED'] === 'true') {
$clarityId = $_ENV['CLARITY_ID'];
echo <<<EOL
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "$clarityId");
</script>
EOL;
}
if ($_ENV['GA_ENABLED'] === 'true') {
$gaId = $_ENV['GA_ID'];
echo <<<EOL
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=$gaId"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '$gaId');
</script>
EOL;
}
?>
</head> </head>
<body class="d-flex flex-column h-100"> <body class="d-flex flex-column h-100">
<?php $this->beginBody() ?> <?php $this->beginBody() ?>

View File

@ -24,10 +24,38 @@ $darkMode = Yii::$app->user->isGuest ? 0 : Yii::$app->user->identity->dark_mode;
?> ?>
<?php $this->beginPage() ?> <?php $this->beginPage() ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>" class="h-100" <?= $darkMode===1?'data-bs-theme="dark"':''?> > <html lang="<?= Yii::$app->language ?>" class="h-100" <?= $darkMode === 1 ? 'data-bs-theme="dark"' : '' ?> >
<head> <head>
<title><?= Html::encode($this->title).' | '.Yii::$app->name ?></title> <title><?= Html::encode($this->title) . ' | ' . Yii::$app->name ?></title>
<?php $this->head() ?> <?php $this->head() ?>
<?php
if ($_ENV['CLARITY_ENABLED'] === 'true') {
$clarityId = $_ENV['CLARITY_ID'];
echo <<<EOL
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "$clarityId");
</script>
EOL;
}
if ($_ENV['GA_ENABLED'] === 'true') {
$gaId = $_ENV['GA_ID'];
echo <<<EOL
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=$gaId"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '$gaId');
</script>
EOL;
}
?>
</head> </head>
<body class="d-flex flex-column h-100"> <body class="d-flex flex-column h-100">
<?php $this->beginBody() ?> <?php $this->beginBody() ?>
@ -90,9 +118,9 @@ $darkMode = Yii::$app->user->isGuest ? 0 : Yii::$app->user->identity->dark_mode;
</body> </body>
</html> </html>
<?php <?php
if($darkMode===2){ if ($darkMode === 2) {
$this->registerJsFile('@web/js/darkmode_auto.js', ['position' => View::POS_BEGIN]); $this->registerJsFile('@web/js/darkmode_auto.js', ['position' => View::POS_BEGIN]);
}else if ($darkMode===1){ } else if ($darkMode === 1) {
$this->registerJsFile('@web/js/darkmode.js', ['position' => View::POS_BEGIN]); $this->registerJsFile('@web/js/darkmode.js', ['position' => View::POS_BEGIN]);
} }
?> ?>