Skip to content

Commit

Permalink
initial commit of basic setup
Browse files Browse the repository at this point in the history
  • Loading branch information
iainsgillis committed Nov 20, 2020
0 parents commit 7a2dcdf
Show file tree
Hide file tree
Showing 21 changed files with 1,097 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# v0.1.0
## 11/20/2020

1. [](#new)
* Plugin started...
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Iain Gillis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Plausible Analytics Plugin

**This README.md file should be modified to describe the features, installation, configuration, and general usage of the plugin.**

The **Plausible Analytics** Plugin is an extension for [Grav CMS](http://github.com/getgrav/grav). Integrate Plausible Analytics into your Grav site and configure it from your admin panel.

## Installation

Installing the Plausible Analytics plugin can be done in one of three ways: The GPM (Grav Package Manager) installation method lets you quickly install the plugin with a simple terminal command, the manual method lets you do so via a zip file, and the admin method lets you do so via the Admin Plugin.

### GPM Installation (Preferred)

To install the plugin via the [GPM](http://learn.getgrav.org/advanced/grav-gpm), through your system's terminal (also called the command line), navigate to the root of your Grav-installation, and enter:

bin/gpm install plausible-analytics

This will install the Plausible Analytics plugin into your `/user/plugins`-directory within Grav. Its files can be found under `/your/site/grav/user/plugins/plausible-analytics`.

### Manual Installation

To install the plugin manually, download the zip-version of this repository and unzip it under `/your/site/grav/user/plugins`. Then rename the folder to `plausible-analytics`. You can find these files on [GitHub](https://github.com/iainsgillis/grav-plugin-plausible-analytics) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).

You should now have all the plugin files under

/your/site/grav/user/plugins/plausible-analytics

> NOTE: This plugin is a modular component for Grav which may require other plugins to operate, please see its [blueprints.yaml-file on GitHub](https://github.com/iainsgillis/grav-plugin-plausible-analytics/blob/master/blueprints.yaml).
### Admin Plugin

If you use the Admin Plugin, you can install the plugin directly by browsing the `Plugins`-menu and clicking on the `Add` button.

## Configuration

Before configuring this plugin, you should copy the `user/plugins/plausible-analytics/plausible-analytics.yaml` to `user/config/plugins/plausible-analytics.yaml` and only edit that copy.

Here is the default configuration and an explanation of available options:

```yaml
enabled: true
```
Note that if you use the Admin Plugin, a file with your configuration named plausible-analytics.yaml will be saved in the `user/config/plugins/`-folder once the configuration is saved in the Admin.

## Usage

**Describe how to use the plugin.**

## Credits

**Did you incorporate third-party code? Want to thank somebody?**

## To Do

- [ ] Future plans, if any

36 changes: 36 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Plausible Analytics
slug: plausible
type: plugin
version: 0.1.0
description: Integrate Plausible Analytics into your Grav site.
icon: bar-chart
author:
name: Iain Gillis
email: iain@iainsgillis.com
homepage: https://github.com/iainsgillis/grav-plugin-plausible
# demo: http://demo.yoursite.com
keywords: grav, plugin, plausible, analytics
bugs: https://github.com/iainsgillis/grav-plugin-plausible/issues
docs: https://github.com/iainsgillis/grav-plugin-plausible/blob/develop/README.md
license: MIT

dependencies:
- { name: grav, version: ">=1.6.0" }

form:
validation: strict
fields:
enabled:
type: toggle
label: PLUGIN_ADMIN.PLUGIN_STATUS
highlight: 1
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
data_domain:
type: text
label: PLUGIN_PLAUSIBLE.DATA_DOMAIN
help: PLUGIN_PLAUSIBLE.DATA_DOMAIN_HELP
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "iainsgillis/plausible",
"type": "grav-plugin",
"description": "Integrate Plausible Analytics into your Grav site and configure it from your admin panel.",
"keywords": [
"plugin"
],
"homepage": "https://github.com/iainsgillis/grav-plugin-plausible",
"license": "MIT",
"authors": [
{
"name": "Iain Gillis",
"email": "iain@iainsgillis.com",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.3"
},
"autoload": {
"psr-4": {
"Grav\\Plugin\\Plausible\\": "classes/"
},
"classmap": [
"plausible.php"
]
},
"config": {
"platform": {
"php": "7.1.3"
}
}
}
23 changes: 23 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions languages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
PLUGIN_PLAUSIBLE:
DATA_DOMAIN: Domain
DATA_DOMAIN_HELP: Just the naked domain without www or https://. You'll need to add your site to plausible.io if you haven't already.
54 changes: 54 additions & 0 deletions plausible.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Grav\Plugin;

use Composer\Autoload\ClassLoader;
use Grav\Common\Plugin;

/**
* Class PlausiblePlugin
* @package Grav\Plugin
*/
class PlausiblePlugin extends Plugin
{
/**
* @return array
* The getSubscribedEvents() gives the core a list of events
*
* that the plugin wants to listen to. The key of each
* array section is the event that the plugin listens to
* and the value (in the form of an array) contains the
* callable (or function) as well as the priority. The
* higher the number the higher the priority.
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => [
['autoload', 100000], // TODO: Remove when plugin requires Grav >=1.7
['onAssetsInitialized', 0],
]
];
}

/**
* Composer autoload.
*is
* @return ClassLoader
*/
public function autoload(): ClassLoader
{
return require __DIR__ . '/vendor/autoload.php';
}

public function onAssetsInitialized()
{
// Don't proceed if we are in the admin plugin
if ($this->isAdmin()) {
return;
}
$plausibleDomain = $this->config->get('plugins.plausible.data_domain', 'example.com');
$plausibleSrcUrl = "https://plausible.io/js/plausible.js";
$this->grav['assets']->addJs($plausibleSrcUrl, ['loading' => 'async defer', 'data-domain' => $plausibleDomain]);
}
}
4 changes: 4 additions & 0 deletions plausible.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enabled: true
active: true
data_domain: example.com
data_domain_help: Just the naked domain without www or https://. You'll need to add your site to plausible.io if you haven't already.
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit4a33c9d5e4efdcb2ad7f8676cf95f3bc::getLoader();
Loading

0 comments on commit 7a2dcdf

Please sign in to comment.