1
0
mirror of https://github.com/typemill/typemill.git synced 2025-10-18 16:16:08 +02:00

Version 1.1.1 Theme and Plugin Optimizations

This commit is contained in:
Sebastian
2018-02-25 17:29:38 +01:00
parent 5deaf6f7ca
commit c43c633cb4
787 changed files with 58749 additions and 242 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Plugins\Analytics;
use \Typemill\Plugin;
class Analytics extends Plugin
{
protected $settings;
public static function getSubscribedEvents()
{
return array(
'onSettingsLoaded' => 'onSettingsLoaded',
'onTwigLoaded' => 'onTwigLoaded'
);
}
public function onSettingsLoaded($settings)
{
$this->settings = $settings->getData();
}
public function onTwigLoaded()
{
/* get Twig Instance and add the cookieconsent template-folder to the path */
$twig = $this->getTwig();
$loader = $twig->getLoader();
$loader->addPath(__DIR__ . '/templates');
$analyticSettings = $this->settings['settings']['plugins']['analytics'];
/* fetch the template, render it with twig and add javascript with settings */
if($analyticSettings['tool'] == 'piwik')
{
$this->addInlineJS($twig->fetch('/piwikanalytics.twig', $this->settings));
}
elseif($analyticSettings['tool'] == 'google')
{
$this->addJS('https://www.googletagmanager.com/gtag/js?id=' . $analyticSettings['google_id']);
$this->addInlineJS($twig->fetch('/googleanalytics.twig', $analyticSettings));
}
}
}

View File

@@ -0,0 +1,38 @@
name: Analytics
version: 1.0.0
description: Integrate Piwik or Google Analytics Script
author: Sebastian Schürmanns
homepage: http://typemill.net
licence: MIT
settings:
tool: none
forms:
fields:
tool:
type: radio
label: Choose Your Tool
options:
none: None
piwik: Piwik
google: Google Analytics
piwik_url:
type: text
label: Piwik URL
help: Add the URL to your piwik installation without protocol like this: my-site.com.
placeholder: 'url like my-piwik-installation.com'
piwik_id:
type: number
label: Piwik Site-ID
help: You can find the id in Piwik under configuration and tracking code.
placeholder: 'simple number like 8'
google_id:
type: text
label: Google Tracking ID
help: You can find the tracking id in google under property. It starts with UA-
placeholder: 'UA-12345-6'

View File

@@ -0,0 +1,5 @@
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ google_id }}');

View File

@@ -0,0 +1,11 @@
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function(){
var u="//{{ settings.plugins.analytics.piwik_url }}/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '{{ settings.plugins.analytics.piwik_id }}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();