Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iskrisis committed Apr 20, 2021
0 parents commit 8a65ebe
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "floriankarsten/kirby-plausible",
"description": "",
"type": "kirby-plugin",
"license": "MIT",
"authors": [
{
"name": "Florian Karsten",
"email": "[email protected]"
}
],
"require": {
"getkirby/composer-installer": "^1.1",
"php": ">=7.4.0"
},
"autoload": {
},
"config": {
"optimize-autoloader": true
}
}
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
panel.plugin("floriankarsten/plausible", {
views: {
plausible: {
label: 'Analytics',
icon: "road-sign",
component: {
template: `
<div class="k-plausible-view">
<div style="margin-top: 30px; text-align: center;" v-if="showError">
<code>You need to set floriankarsten.plausible.sharedLink in config.php</code>
</div>
<iframe v-if="sharedLink" plausible-embed v-bind:src="sharedLink" scrolling="no" frameborder="0" loading="lazy" style="width: 1px; min-width: 100%; height: 1600px;"></iframe>
</div>`,
data: function() {
return {
options: {},
showError: false,
sharedLink: ","
};
},
created: function() {
this.$api
.get("plausible")
.then(options => {
if(!options.sharedLink) {
this.showError = true;
} else {
this.sharedLink = options.sharedLink + "&embed=true&theme=light"
}
});
}
},
}
}
});
17 changes: 17 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

Kirby::plugin('floriankarsten/plausible', [
'api' => [
'routes' => [
[
'pattern' => 'plausible',
'action' => function () {
return option('floriankarsten.plausible');
}
]
]
],
'snippets' => [
'plausible' => __DIR__ . '/snippets/plausible.php'
]
]);
21 changes: 21 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Kirby Plausible
Simple plugin providing plausible iframe panel view to kirby panel and simple frontend snippet.

## How to use
1. Create a shared link https://plausible.io/docs/shared-links
2. Set `floriankarsten.plausible.shareLink` in config.php

There is also `floriankarsten.plausible.domain` which allows you to overwrite `data-domain` in the frontend snippet.

config.php example
```php
'floriankarsten.plausible' => [
'sharedLink' => 'https://plausible.io/share/yourwebsiteurl.com?auth=Jz0mCWTPu5opXi0sAgRrq',
'domain' => 'test.com' // not required if not set it will be taken from $site->url
];
```

Frontend snippet place iside head tag. Automatically disabled when kirby is in debug mode.
```php
<?php snippet('plausible'); ?>
```
3 changes: 3 additions & 0 deletions snippets/plausible.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php if(option('debug') === false): ?>
<script async defer data-domain="<?= option('floriankarsten.plausible.domain') ?? parse_url($kirby->url('index'))['host'] ?>" src="https://plausible.io/js/plausible.js"></script>
<?php endif; ?>

0 comments on commit 8a65ebe

Please sign in to comment.