Support Plausible.io Analytics

This commit is contained in:
Stéphane Goetz 2020-04-24 22:22:57 +02:00
parent 9383fa5f94
commit 213b33b9b5
8 changed files with 58 additions and 41 deletions

View File

@ -77,7 +77,7 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Generate documentation
run: bin/daux generate
run: bin/daux generate --value html.plausible_domain=daux.io
- uses: JamesIves/github-pages-deploy-action@2.0.3
env:
FOLDER: "static"

View File

@ -30,6 +30,15 @@ You can Also give a specific Piwik ID as well.
}
```
### Plausible Analytics
This will embed the https://plausible.io/ tracking code.
```json
{
"html": { "plausible_domain": "daux.io" }
}
```
## Automatic Table of Contents
You can add a table of contents on each page automatically, read about it [here](../01_Features/Table_of_contents.md)

View File

@ -69,18 +69,3 @@ docker run --rm -it -w /build -v "$PWD":/build daux/daux.io daux generate
```
---
<!-- Google Code -->
<script type="text/javascript">
var google_conversion_id = 983836026;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/983836026/?value=0&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

View File

@ -21,13 +21,13 @@
"repo": "dauxio/daux.io",
"edit_on_github": "dauxio/daux.io/blob/master/docs",
"twitter": ["onigoetz"],
"google_analytics": "UA-3551397-7",
"google_analytics": false,
"plausible_domain": false,
"links": {
"Download": "https://github.com/dauxio/daux.io/archive/master.zip",
"GitHub Repo": "https://github.com/dauxio/daux.io",
"Help/Support/Bugs": "https://github.com/dauxio/daux.io/issues"
},
"powered_by": "Powered by Daux.io"
},
"confluence": {

View File

@ -5,6 +5,9 @@ class ConfigBuilder
/** @var Config */
private $config;
/** @var array */
private $overrideValues = [];
private $configuration_override_file;
private function __construct(string $mode)
@ -34,7 +37,7 @@ class ConfigBuilder
return $this;
}
private function setValue(&$array, $key, $value)
private function setValue(Config $array, $key, $value)
{
if (is_null($key)) {
return $array = $value;
@ -48,15 +51,11 @@ class ConfigBuilder
$array = &$array[$key];
}
$array[array_shift($keys)] = $value;
return $array;
}
public function withValues(array $values): ConfigBuilder
{
foreach ($values as $value) {
$this->setValue($this->config, $value[0], $value[1]);
}
$this->overrideValues = $values;
return $this;
}
@ -128,6 +127,10 @@ class ConfigBuilder
{
$this->initializeConfiguration();
foreach ($this->overrideValues as $value) {
$this->setValue($this->config, $value[0], $value[1]);
}
return $this->config;
}

View File

@ -76,6 +76,16 @@ class Config extends BaseConfig
return $this->getValue('google_analytics');
}
public function hasPlausibleAnalyticsDomain()
{
return $this->hasValue('plausible_domain') && $this->getValue('plausible_domain');
}
public function getPlausibleAnalyticsDomain()
{
return $this->getValue('plausible_domain');
}
public function hasPiwikAnalytics()
{
return $this->getValue('piwik_analytics') && $this->hasValue('piwik_analytics_id');

View File

@ -2,19 +2,26 @@
<html class="no-js" lang="<?=$config->getLanguage() ?>">
<head>
<title><?= $page['title']; ?> <?= ($page['title'] != $config->getTitle()) ? '- ' . $config->getTitle() : "" ?></title>
<?php //SEO meta tags...
<?php
//SEO meta tags...
$meta = [];
if (array_key_exists('attributes', $page) && array_key_exists('description', $page['attributes'])) {
echo " <meta name=\"description\" content=\"{$page['attributes']['description']}\">\n";
$meta['description'] = $page['attributes']['description'];
} elseif ($config->hasTagline()) {
echo " <meta name=\"description\" content=\"{$config->getTagline()}\">\n";
$meta['description'] = $config->getTagLine();
}
if (array_key_exists('attributes', $page) && array_key_exists('keywords', $page['attributes'])) {
echo " <meta name=\"keywords\" content=\"{$page['attributes']['keywords']}\">\n";
$meta['keywords'] = $page['attributes']['keywords'];
}
if (array_key_exists('attributes', $page) && array_key_exists('author', $page['attributes'])) {
echo " <meta name=\"author\" content=\"{$page['attributes']['author']}\">\n";
$meta['author'] = $page['attributes']['author'];
} elseif ($config->hasAuthor()) {
echo " <meta name=\"author\" content=\"{$config->getAuthor()}\">\n";
$meta['author'] = $config->getAuthor();
}
foreach ($meta as $name => $content) {
echo " <meta name=\"{$name}\" content=\"{$content}\">\n";
}
?>
<meta charset="UTF-8">
@ -28,19 +35,19 @@
<!-- JS -->
<script>
window.base_url = "<?php echo $base_url?>";
window.base_url = "<?= $base_url?>";
document.documentElement.classList.remove('no-js');
</script>
<!-- Font -->
<?php foreach ($config->getTheme()->getFonts() as $font) {
echo "<link href='$font' rel='stylesheet' type='text/css'>";
} ?>
<?php foreach ($config->getTheme()->getFonts() as $font) { ?>
<link href='<?= $font; ?>' rel='stylesheet' type='text/css'>
<?php } ?>
<!-- CSS -->
<?php foreach ($config->getTheme()->getCSS() as $css) {
echo "<link href='$css' rel='stylesheet' type='text/css'>";
} ?>
<?php foreach ($config->getTheme()->getCSS() as $css) { ?>
<link href='<?= $css; ?>' rel='stylesheet' type='text/css'>
<?php } ?>
<?php if ($config->getHTML()->hasSearch()) { ?>
<!-- Search -->
@ -57,14 +64,16 @@
if ($config->getHTML()->hasPiwikAnalytics()) {
$this->insert('theme::partials/piwik_analytics', ['url' => $config->getHTML()->getPiwikAnalyticsUrl(), 'id' => $config->getHTML()->getPiwikAnalyticsId()]);
}
if ($config->getHTML()->hasPlausibleAnalyticsDomain()) {
$this->insert('theme::partials/plausible_analytics', ['domain' => $config->getHTML()->getPlausibleAnalyticsDomain()]);
}
?>
<!-- JS -->
<?php foreach ($config->getTheme()->getJS() as $js) {
echo '<script src="' . $js . '"></script>';
} ?>
<?php foreach ($config->getTheme()->getJS() as $js) { ?>
<script src="<?= $js; ?>"></script>
<?php } ?>
<?php $this->insert('theme::partials/search_script', ['page' => $page, 'base_url' => $base_url]); ?>
</body>
</html>

View File

@ -0,0 +1 @@
<script async defer data-domain="<?= $domain ?>" src="https://plausible.io/js/plausible.js"></script>