From 661648f1c263d6d8aa939400fdf50c993676bbc2 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Thu, 22 Dec 2016 13:18:05 +0100 Subject: [PATCH 01/17] Initialize Release 1.4.0 --- LICENSE | 2 +- blueprints.yaml | 2 +- ganalytics.php | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 484793a..0b67f50 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Grav +Copyright (c) 2016 John Linhart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/blueprints.yaml b/blueprints.yaml index 2010ed2..30a25b0 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Google Analytics -version: 1.3.0 +version: 1.4.0 description: "Google Analytics plugin lets you easyly embed the GA tracking to the Grav website." icon: google author: diff --git a/ganalytics.php b/ganalytics.php index 55a2c1f..076c62d 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -69,13 +69,14 @@ private function getTrackingSettings($trackingId, $gaName) */ public function onAssetsInitialized() { - if ($this->isAdmin()) return; // Return if we are in the Admin Plugin + // Don't proceed if we are in the admin plugin + if ($this->isAdmin()) return; // Get the GA Tracking ID $trackingId = trim($this->config->get('plugins.ganalytics.trackingId', '')); if (empty($trackingId)) return; - // Maybe the IP is blocked + // Don't proceed if the IP address is blocked $blockedIps = $this->config->get('plugins.ganalytics.blockedIps', []); if (in_array($_SERVER['REMOTE_ADDR'], $blockedIps)) return; From 6e18d680f7e0859ecf576056fcd0ac7fa2f4405a Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Thu, 22 Dec 2016 13:52:31 +0100 Subject: [PATCH 02/17] general stuff --- .editorconfig | 16 ++++++++++++++++ .gitignore | 2 +- README.md | 2 +- blueprints.yaml | 1 + ganalytics.yaml | 13 +++++++------ 5 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8fe02d3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# top-most EditorConfig file +root = true + +# All files +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +# 4 space indentation for PHP +[*.php, *.inc] +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 723ef36..a09c56d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -.idea \ No newline at end of file +/.idea diff --git a/README.md b/README.md index 1a90b5d..33e25a0 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ enabled: true # Global enable/disable the entire plugin trackingId: '' # GA Tracking ID `REQUIRED` renameGa: '' # Other name for the global (ga) variable anonymizeIp: false # Enable/Disable IP Anonymization -blockedIps: # Array of blocked IPs +blockedIps: [] # Array of blocked IPs debugStatus: false # Enable/disable Debugging debugTrace: false # Enable/Disable Trace Debugging ``` diff --git a/blueprints.yaml b/blueprints.yaml index 30a25b0..11bb954 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -9,6 +9,7 @@ author: homepage: https://github.com/escopecz/grav-ganalytics keywords: google, plugin, tracking, analytics, grav bugs: https://github.com/escopecz/grav-ganalytics/issues +docs: https://github.com/escopecz/grav-ganalytics/blob/master/README.md license: MIT form: diff --git a/ganalytics.yaml b/ganalytics.yaml index 4f3a0fe..fc00c98 100644 --- a/ganalytics.yaml +++ b/ganalytics.yaml @@ -1,6 +1,7 @@ -enabled: true # global enable/disable the entire plugin -trackingId: '' # GA tracking ID -anonymizeIp: false # IP Anonymization -renameGa: '' # GA Object renaming -debugStatus: false # Debugging Enabled/Disabled -debugTrace: false # Trace Debugging Enabled/Disabled \ No newline at end of file +enabled: true # Global enable/disable the entire plugin +trackingId: '' # GA Tracking ID `REQUIRED` +renameGa: '' # Other name for the global (ga) variable +anonymizeIp: false # Enable/Disable IP Anonymization +blockedIps: [] # Array of blocked IP addresses +debugStatus: false # Enable/disable Debugging +debugTrace: false # Enable/Disable Trace Debugging \ No newline at end of file From af2becb26b0e9bbd4065b5003fa587d04427612d Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Thu, 22 Dec 2016 14:45:46 +0100 Subject: [PATCH 03/17] Feature: Alternative async tracking --- blueprints.yaml | 12 ++++++++++++ ganalytics.php | 41 ++++++++++++++++++++++++++++------------- ganalytics.yaml | 1 + languages.yaml | 4 ++++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/blueprints.yaml b/blueprints.yaml index 11bb954..f8cbf94 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -53,6 +53,18 @@ form: size: small placeholder: "ga" + async: + type: toggle + label: PLUGIN_GANALYTICS.ASYNC + help: PLUGIN_GANALYTICS.ASYNC_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + anonymizeIp: type: toggle label: PLUGIN_GANALYTICS.ANONYMIZE_IP diff --git a/ganalytics.php b/ganalytics.php index 076c62d..04592fb 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -29,18 +29,27 @@ public static function getSubscribedEvents() /** * Return the Google Analytics Tracking Code + * @param string $scriptName Name of the GA script library * @param string $gaName Global variable name for the GA object + * @param bool $async Determine if the GA script should be loaded and executed asynchronously * @return string */ - private function getTrackingCode($gaName) + private function getTrackingCode($scriptName, $gaName, $async=false) { - $script = $this->config->get('plugins.ganalytics.debugStatus', false) ? 'analytics_debug.js' : 'analytics.js'; - return - "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n". - "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n". - "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n". - "})(window,document,'script','//www.google-analytics.com/{$script}','{$gaName}');\n\n" - ; + if ($async) { + $code = + "window.GoogleAnalyticsObject = '{$gaName}';\n". + "window.{$gaName}=window.{$gaName}||function(){({$gaName}.q={$gaName}.q||[]).push(arguments)};{$gaName}.l=+new Date;\n" + ; + } else { + $code = + "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n". + "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n". + "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n". + "})(window,document,'script','//www.google-analytics.com/{$scriptName}.js','{$gaName}');\n" + ; + } + return $code; } /** @@ -72,23 +81,29 @@ public function onAssetsInitialized() // Don't proceed if we are in the admin plugin if ($this->isAdmin()) return; - // Get the GA Tracking ID + // Parameters $trackingId = trim($this->config->get('plugins.ganalytics.trackingId', '')); + $scriptName = $this->config->get('plugins.ganalytics.debugStatus', false) ? 'analytics_debug' : 'analytics'; + $async = $this->config->get('plugins.ganalytics.async', false); + $blockedIps = $this->config->get('plugins.ganalytics.blockedIps', []); + $gaName = trim($this->config->get('plugins.ganalytics.renameGa', '')); + + // Don't proceed if there is no GA Tracking ID if (empty($trackingId)) return; // Don't proceed if the IP address is blocked - $blockedIps = $this->config->get('plugins.ganalytics.blockedIps', []); if (in_array($_SERVER['REMOTE_ADDR'], $blockedIps)) return; - // Global (ga) variable - $gaName = trim($this->config->get('plugins.ganalytics.renameGa', '')); + // Set the global (ga) variable name if (empty($gaName)) $gaName = 'ga'; // Tracking Code and settings $settings = $this->getTrackingSettings($trackingId, $gaName); - $code = $this->getTrackingCode($gaName); + $code = $this->getTrackingCode($scriptName, $gaName, $async); $code.= join(PHP_EOL, $settings); + // Embed Goggle Analytics script $this->grav['assets']->addInlineJs($code); + if ($async) $this->grav['assets']->addAsyncJs("//www.google-analytics.com/{$scriptName}.js"); } } diff --git a/ganalytics.yaml b/ganalytics.yaml index fc00c98..1fbc81d 100644 --- a/ganalytics.yaml +++ b/ganalytics.yaml @@ -1,6 +1,7 @@ enabled: true # Global enable/disable the entire plugin trackingId: '' # GA Tracking ID `REQUIRED` renameGa: '' # Other name for the global (ga) variable +async: false # Enable/Disable Asynchronously Tracking anonymizeIp: false # Enable/Disable IP Anonymization blockedIps: [] # Array of blocked IP addresses debugStatus: false # Enable/disable Debugging diff --git a/languages.yaml b/languages.yaml index dbecc5d..67f020a 100644 --- a/languages.yaml +++ b/languages.yaml @@ -5,6 +5,8 @@ en: SECTION_DEBUG: "Debug" TACKING_ID: "Tracking ID" TACKING_ID_HELP: "Google Analytics Tracking ID" + ASYNC: "Asynchronously" + ASYNC_HELP: "Allow modern browsers to preload the Google Analytics script" ANONYMIZE_IP: "IP Anonymization" ANONYMIZE_IP_HELP: "Enable the anonymization of the IP address" RENAME_GA: "(ga) Variable" @@ -23,6 +25,8 @@ de: SECTION_DEBUG: "Debugging" TACKING_ID: "Tracking-ID" TACKING_ID_HELP: "Google Analytics Tracking-ID" + ASYNC: "Asynchron" + ASYNC_HELP: "Erlaubt es modernen Browsern das Google Analytics Script im Voraus zu laden" ANONYMIZE_IP: "IP-Anonymisierung" ANONYMIZE_IP_HELP: "Aktiviert die Anonymisierung der IP-Adresse" RENAME_GA: "(ga) Variable" From d861d9bfdcc254016f99146da1b490e7bc59f8bb Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Thu, 22 Dec 2016 17:27:58 +0100 Subject: [PATCH 04/17] Update README.md --- README.md | 72 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 33e25a0..44234ee 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,69 @@ -# Google Analytics Grav Plugin +# Grav Google Analytics Plugin -This is [Grav CMS](http://getgrav.org) plugin that helps you implement [Google Analytics](https://www.google.com/analytics) tracking code into your website. That way your GA tracking will be theme-independent. +The **Google Analytics** Plugin for [Grav CMS](http://github.com/getgrav/grav) allows you to integrate and configure [Google Analytics](https://www.google.com/analytics) without the need to touch any code within your Grav site. -# Installation +### Features +* Asynchronous/Synchronous Integration +* IP Anonymization +* Renaming of the Global (ga) Object +* Debug Mode with Trace Debugging +* Blocking IP Addresses +* Multi-Language Support for the [Grav Administration Panel](https://github.com/getgrav/grav-plugin-admin) -Installing the Google Analytics plugin can be done in one of two ways. +## Installation -## GPM Installation (Preferred) +Installing the Google Analytics plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file. -The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type: +### GPM Installation (Preferred) + +The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's terminal (also called the command line). From the root of your Grav install type: bin/gpm install ganalytics This will install the Google Analytics plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/ganalytics`. -## Manual Installation +### Manual Installation -To install this plugin, just [download](https://github.com/escopecz/grav-ganalytics/archive/master.zip) the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `ganalytics`. +To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `ganalytics`. You can find these files on [GitHub](https://github.com/escopecz/grav-ganalytics) or via [GetGrav.org](http://getgrav.org/downloads/plugins). You should now have all the plugin files under /your/site/grav/user/plugins/ganalytics + +> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav) to operate. -# Config Defaults +## Configuration -``` -enabled: true # Global enable/disable the entire plugin -trackingId: '' # GA Tracking ID `REQUIRED` -renameGa: '' # Other name for the global (ga) variable -anonymizeIp: false # Enable/Disable IP Anonymization -blockedIps: [] # Array of blocked IPs -debugStatus: false # Enable/disable Debugging -debugTrace: false # Enable/Disable Trace Debugging -``` +Before configuring this plugin, you should copy the `user/plugins/ganalytics/ganalytics.yaml` to `user/config/plugins/ganalytics.yaml` and only edit that copy. -If you need to change any value, then the best process is to copy the [ganalytics.yaml](ganalytics.yaml) file into your `users/config/plugins/` folder (create it if it doesn't exist), and then modify there. This will override the default settings. +Here is the default configuration and an explanation of available options: -# Usage +```yaml +enabled: true +trackingId: '' +renameGa: '' +async: false +anonymizeIp: false +blockedIps: [] +debugStatus: false +debugTrace: false +``` -1. In your Google Analytics account, open the analytics of the Grav website (or create new if doesn't exist yet). -2. Go to *Admin* / *Tracking Info* / *Tracking Code* -3. Copy the *Tracking ID* and insert it to the configuration of this plugin. +* `enabled` Toggles if the Google Analytics plugin is turned on or off +* `trackingId` The Google Analytics Tracking ID. This value is **required**. +* `async` Toggles if Google Analytics script is loaded and executed asynchronously. +* `renameGa` In some cases you'd like to add Google Analytics to your page, but the `ga` variable is already being used for something else. To deal with this, you can just rename the global ga object. +* `anonymizeIp` Toggles if Google Analytics will anonymize the IP address for all hits. +* `blockedIps` Here you can blacklist IP addresses. For those the Google Analytics script will not be embedded. +* `debugStatus` Toggles if the debug version of Goggle Analytics is enabled or disabled. +* `debugTrace` Toggles if the debugger will output more verbose information to the console. `debugStatus` must be enabled. + +## Usage + +1. Sign in to your [Google Analytics account](https://www.google.com/analytics/web/#home). +2. Select the **Admin** tab. +3. Select an account from the dropdown in the _ACCOUNT_ column. +4. Select a property from the dropdown in the _PROPERTY_ column. +5. Under _PROPERTY_, click **Tracking Info > Tracking Code**. +6. Copy the **Tracking ID** (a string like _UA-000000-01_) +7. Add it to the configuration of this plugin. From c488a5de8036873394426765e9aa5936dc722b2e Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Fri, 23 Dec 2016 11:04:04 +0100 Subject: [PATCH 05/17] Feature: Force SSL --- CHANGELOG.md | 7 +++++++ README.md | 4 +++- blueprints.yaml | 12 ++++++++++++ ganalytics.php | 2 ++ ganalytics.yaml | 1 + languages.yaml | 4 ++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56682af..0746aab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v1.4.0 +## 12/xx/2016 + +1. [](#new) + * Force SSL - Send all data using SSL, even from insecure (HTTP) pages + * Asynchronously Integration - Google Analytic script can be loaded and executed asynchronously + # v1.3.0 ## 12/21/2016 diff --git a/README.md b/README.md index 44234ee..73d757f 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ enabled: true trackingId: '' renameGa: '' async: false +forceSsl: false anonymizeIp: false blockedIps: [] debugStatus: false @@ -52,7 +53,8 @@ debugTrace: false * `enabled` Toggles if the Google Analytics plugin is turned on or off * `trackingId` The Google Analytics Tracking ID. This value is **required**. * `async` Toggles if Google Analytics script is loaded and executed asynchronously. -* `renameGa` In some cases you'd like to add Google Analytics to your page, but the `ga` variable is already being used for something else. To deal with this, you can just rename the global ga object. +* `forceSsl` Toggles if Google Analytics should send all data using HTTPS. +* `renameGa` In some cases you'd like to add Google Analytics to your page, but the `ga` variable is already being used for something else. To deal with this, you can rename the global ga object. * `anonymizeIp` Toggles if Google Analytics will anonymize the IP address for all hits. * `blockedIps` Here you can blacklist IP addresses. For those the Google Analytics script will not be embedded. * `debugStatus` Toggles if the debug version of Goggle Analytics is enabled or disabled. diff --git a/blueprints.yaml b/blueprints.yaml index f8cbf94..607c781 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -65,6 +65,18 @@ form: validate: type: bool + forceSsl: + type: toggle + label: PLUGIN_GANALYTICS.FORCE_SSL + help: PLUGIN_GANALYTICS.FORCE_SSL_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + anonymizeIp: type: toggle label: PLUGIN_GANALYTICS.ANONYMIZE_IP diff --git a/ganalytics.php b/ganalytics.php index 04592fb..1f8c798 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -64,11 +64,13 @@ private function getTrackingSettings($trackingId, $gaName) 'trace-debug' => "window.ga_debug = {trace: true};", 'create' => "{$gaName}('create', '{$trackingId}', 'auto');", 'anonymize' => "{$gaName}('set', 'anonymizeIp', true);", + 'force-ssl' => "{$gaName}('set', 'forceSSL', true);", 'send' => "{$gaName}('send', 'pageview');" ]; if (!$this->config->get('plugins.ganalytics.debugTrace', false)) unset ($settings['trace-debug']); if (!$this->config->get('plugins.ganalytics.anonymizeIp', false)) unset ($settings['anonymize']); + if (!$this->config->get('plugins.ganalytics.forceSsl', false)) unset ($settings['force-ssl']); return $settings; } diff --git a/ganalytics.yaml b/ganalytics.yaml index 1fbc81d..2e07aa9 100644 --- a/ganalytics.yaml +++ b/ganalytics.yaml @@ -1,6 +1,7 @@ enabled: true # Global enable/disable the entire plugin trackingId: '' # GA Tracking ID `REQUIRED` renameGa: '' # Other name for the global (ga) variable +forceSsl: false # Enable/Disable SSL async: false # Enable/Disable Asynchronously Tracking anonymizeIp: false # Enable/Disable IP Anonymization blockedIps: [] # Array of blocked IP addresses diff --git a/languages.yaml b/languages.yaml index 67f020a..76ab79f 100644 --- a/languages.yaml +++ b/languages.yaml @@ -7,6 +7,8 @@ en: TACKING_ID_HELP: "Google Analytics Tracking ID" ASYNC: "Asynchronously" ASYNC_HELP: "Allow modern browsers to preload the Google Analytics script" + FORCE_SSL: "Force SSL" + FORCE_SSL_HELP: "Send all data using SSL, even from insecure (HTTP) pages" ANONYMIZE_IP: "IP Anonymization" ANONYMIZE_IP_HELP: "Enable the anonymization of the IP address" RENAME_GA: "(ga) Variable" @@ -27,6 +29,8 @@ de: TACKING_ID_HELP: "Google Analytics Tracking-ID" ASYNC: "Asynchron" ASYNC_HELP: "Erlaubt es modernen Browsern das Google Analytics Script im Voraus zu laden" + FORCE_SSL: "SSL erzwingen" + FORCE_SSL_HELP: "Alle Daten werden mit SSL gesendet, auch von unsicheren (HTTP) Seiten" ANONYMIZE_IP: "IP-Anonymisierung" ANONYMIZE_IP_HELP: "Aktiviert die Anonymisierung der IP-Adresse" RENAME_GA: "(ga) Variable" From 1a75ee7b1759adc6394a0c95e4b360db7f5d9f24 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Fri, 23 Dec 2016 11:41:31 +0100 Subject: [PATCH 06/17] Don't use a deprecated function --- README.md | 1 + ganalytics.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73d757f..658300d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ The **Google Analytics** Plugin for [Grav CMS](http://github.com/getgrav/grav) a ### Features * Asynchronous/Synchronous Integration * IP Anonymization +* Force SSL (HTTPS). Send all data using SSL, even from insecure (HTTP) pages. * Renaming of the Global (ga) Object * Debug Mode with Trace Debugging * Blocking IP Addresses diff --git a/ganalytics.php b/ganalytics.php index 1f8c798..48f7f98 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -106,6 +106,6 @@ public function onAssetsInitialized() // Embed Goggle Analytics script $this->grav['assets']->addInlineJs($code); - if ($async) $this->grav['assets']->addAsyncJs("//www.google-analytics.com/{$scriptName}.js"); + if ($async) $this->grav['assets']->addJs("//www.google-analytics.com/{$scriptName}.js", 9 , true /*pipeline*/, 'async'); } } From e75f747ca608ed13068efbea35cd4428c1fd1fb2 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Fri, 23 Dec 2016 12:43:07 +0100 Subject: [PATCH 07/17] Feature: Choose code position --- CHANGELOG.md | 5 +++-- README.md | 13 ++++++++----- blueprints.yaml | 14 +++++++++++++- ganalytics.php | 7 +++++-- ganalytics.yaml | 5 +++-- languages.yaml | 14 +++++++++++--- 6 files changed, 43 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0746aab..c67a6c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ ## 12/xx/2016 1. [](#new) - * Force SSL - Send all data using SSL, even from insecure (HTTP) pages - * Asynchronously Integration - Google Analytic script can be loaded and executed asynchronously + * Preload the Google Analytics script asynchronously + * Choose the Google Analytics code position in the HTML document (head or body). + * Force SSL - Send all data using SSL, even from insecure (HTTP) pages # v1.3.0 ## 12/21/2016 diff --git a/README.md b/README.md index 658300d..d99626e 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ The **Google Analytics** Plugin for [Grav CMS](http://github.com/getgrav/grav) allows you to integrate and configure [Google Analytics](https://www.google.com/analytics) without the need to touch any code within your Grav site. ### Features -* Asynchronous/Synchronous Integration +* Preload the Google Analytics script asynchronously * IP Anonymization +* Choose the Google Analytics code position in the HTML document (head or body). * Force SSL (HTTPS). Send all data using SSL, even from insecure (HTTP) pages. * Renaming of the Global (ga) Object * Debug Mode with Trace Debugging @@ -41,8 +42,9 @@ Here is the default configuration and an explanation of available options: ```yaml enabled: true -trackingId: '' -renameGa: '' +trackingId: "" +position: "head" +renameGa: "" async: false forceSsl: false anonymizeIp: false @@ -51,9 +53,10 @@ debugStatus: false debugTrace: false ``` -* `enabled` Toggles if the Google Analytics plugin is turned on or off +* `enabled` Toggles if the Google Analytics plugin is turned on or off. * `trackingId` The Google Analytics Tracking ID. This value is **required**. -* `async` Toggles if Google Analytics script is loaded and executed asynchronously. +* `position` Code Position in the HTML document (head or body). +* `async` Toggles if the Google Analytics script is preloaded asynchronously. * `forceSsl` Toggles if Google Analytics should send all data using HTTPS. * `renameGa` In some cases you'd like to add Google Analytics to your page, but the `ga` variable is already being used for something else. To deal with this, you can rename the global ga object. * `anonymizeIp` Toggles if Google Analytics will anonymize the IP address for all hits. diff --git a/blueprints.yaml b/blueprints.yaml index 607c781..35c067e 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,6 +1,6 @@ name: Google Analytics version: 1.4.0 -description: "Google Analytics plugin lets you easyly embed the GA tracking to the Grav website." +description: "The Google Analytics Plugin allows you to integrate and configure Google Analytics without the need to touch any code within your Grav site." icon: google author: name: John Linhart @@ -41,6 +41,18 @@ form: validate: required: true + position: + type: toggle + label: PLUGIN_GANALYTICS.POSITION + help: PLUGIN_GANALYTICS.POSITION_HELP + hightlight: 1 + default: head + options: + head: PLUGIN_GANALYTICS.POSITION_HEAD + body: PLUGIN_GANALYTICS.POSITION_BODY + validate: + type: string + Advanced: type: section title: PLUGIN_GANALYTICS.SECTION_ADVANCED diff --git a/ganalytics.php b/ganalytics.php index 48f7f98..539e92b 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -85,6 +85,7 @@ public function onAssetsInitialized() // Parameters $trackingId = trim($this->config->get('plugins.ganalytics.trackingId', '')); + $position = trim($this->config->get('plugins.ganalytics.position', 'head')); $scriptName = $this->config->get('plugins.ganalytics.debugStatus', false) ? 'analytics_debug' : 'analytics'; $async = $this->config->get('plugins.ganalytics.async', false); $blockedIps = $this->config->get('plugins.ganalytics.blockedIps', []); @@ -105,7 +106,9 @@ public function onAssetsInitialized() $code.= join(PHP_EOL, $settings); // Embed Goggle Analytics script - $this->grav['assets']->addInlineJs($code); - if ($async) $this->grav['assets']->addJs("//www.google-analytics.com/{$scriptName}.js", 9 , true /*pipeline*/, 'async'); + $group = ($position == 'body') ? 'bottom' : null; + + $this->grav['assets']->addInlineJs($code, null, $group); + if ($async) $this->grav['assets']->addJs("//www.google-analytics.com/{$scriptName}.js", 9 , true /*pipeline*/, 'async', $group); } } diff --git a/ganalytics.yaml b/ganalytics.yaml index 2e07aa9..9db5b50 100644 --- a/ganalytics.yaml +++ b/ganalytics.yaml @@ -1,6 +1,7 @@ enabled: true # Global enable/disable the entire plugin -trackingId: '' # GA Tracking ID `REQUIRED` -renameGa: '' # Other name for the global (ga) variable +trackingId: "" # GA Tracking ID `REQUIRED` +position: "head" # Code Position in the HTML document +renameGa: "" # Other name for the global (ga) variable forceSsl: false # Enable/Disable SSL async: false # Enable/Disable Asynchronously Tracking anonymizeIp: false # Enable/Disable IP Anonymization diff --git a/languages.yaml b/languages.yaml index 76ab79f..549b46d 100644 --- a/languages.yaml +++ b/languages.yaml @@ -5,7 +5,11 @@ en: SECTION_DEBUG: "Debug" TACKING_ID: "Tracking ID" TACKING_ID_HELP: "Google Analytics Tracking ID" - ASYNC: "Asynchronously" + POSITION: "Code Position" + POSITION_HELP: "Code Position in the HTML document (head or body)" + POSITION_HEAD: "Head" + POSITION_BODY: "End of Body" + ASYNC: "Load asynchronously" ASYNC_HELP: "Allow modern browsers to preload the Google Analytics script" FORCE_SSL: "Force SSL" FORCE_SSL_HELP: "Send all data using SSL, even from insecure (HTTP) pages" @@ -27,7 +31,11 @@ de: SECTION_DEBUG: "Debugging" TACKING_ID: "Tracking-ID" TACKING_ID_HELP: "Google Analytics Tracking-ID" - ASYNC: "Asynchron" + POSITION: "Code-Position" + POSITION_HELP: "Position des Codes im HTML-Dokument (Head oder Body)" + POSITION_HEAD: "Kopf" + POSITION_BODY: "Ende des Inhalts" + ASYNC: "Asynchron laden" ASYNC_HELP: "Erlaubt es modernen Browsern das Google Analytics Script im Voraus zu laden" FORCE_SSL: "SSL erzwingen" FORCE_SSL_HELP: "Alle Daten werden mit SSL gesendet, auch von unsicheren (HTTP) Seiten" @@ -36,7 +44,7 @@ de: RENAME_GA: "(ga) Variable" RENAME_GA_HELP: "Umbenennung der globalen (ga)-Variable für das Google Analytics Objekt" BLOCKED_IPS: "Gesperrte IP-Adressen" - BLOCKED_IPS_HELP: "Für die angegebenen IP-Adressen wird der Google Analytics Code nicht eingebunden." + BLOCKED_IPS_HELP: "Für die angegebenen IP-Adressen wird der Google Analytics Code nicht eingebunden" DEBUG_STATUS: "Debug-Version" DEBUG_STATUS_HELP: "Aktiviert die Debugging-Version der analytics.js Bibliothek" DEBUG_TRACE: "Trace-Debugging" From 330a99d0321e39ed9748dc1c6db2b21997b47b89 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Fri, 23 Dec 2016 15:57:36 +0100 Subject: [PATCH 08/17] Feature: Cookie Configuration + Better use of the global object name --- CHANGELOG.md | 9 ++++-- README.md | 25 ++++++++++++--- blueprints.yaml | 82 +++++++++++++++++++++++++++++++++++++------------ ganalytics.php | 66 +++++++++++++++++++++++++++++---------- ganalytics.yaml | 9 +++++- languages.yaml | 32 +++++++++++++++---- 6 files changed, 172 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c67a6c9..6478e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,12 @@ 1. [](#new) * Preload the Google Analytics script asynchronously - * Choose the Google Analytics code position in the HTML document (head or body). - * Force SSL - Send all data using SSL, even from insecure (HTTP) pages - + * Choose the code position in the HTML document (head or body) + * Custom Cookie Configuration. Name, domain and expiration time are configurable. + * Force SSL - Send all data using SSL, even from insecure (HTTP) pages +1. [](#improved) + * Better use and configuration of the global object name. Please don't use `renameGa` anymore. + # v1.3.0 ## 12/21/2016 diff --git a/README.md b/README.md index d99626e..30f4855 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ The **Google Analytics** Plugin for [Grav CMS](http://github.com/getgrav/grav) a * Force SSL (HTTPS). Send all data using SSL, even from insecure (HTTP) pages. * Renaming of the Global (ga) Object * Debug Mode with Trace Debugging +* Custom Cookie Configuration. Name, domain and expiration time are configurable. * Blocking IP Addresses * Multi-Language Support for the [Grav Administration Panel](https://github.com/getgrav/grav-plugin-admin) @@ -41,26 +42,40 @@ Before configuring this plugin, you should copy the `user/plugins/ganalytics/gan Here is the default configuration and an explanation of available options: ```yaml -enabled: true +enabled: true trackingId: "" + position: "head" -renameGa: "" -async: false +objectName: "ga" forceSsl: false +async: false anonymizeIp: false blockedIps: [] + +cookieConfig: false +cookieName: "_ga" +cookieDomain: "" +cookieExpires: 63072000 + debugStatus: false debugTrace: false ``` * `enabled` Toggles if the Google Analytics plugin is turned on or off. * `trackingId` The Google Analytics Tracking ID. This value is **required**. -* `position` Code Position in the HTML document (head or body). + +* `position` Code Position in the HTML document (`head` or `body`). Default is `head`. * `async` Toggles if the Google Analytics script is preloaded asynchronously. * `forceSsl` Toggles if Google Analytics should send all data using HTTPS. -* `renameGa` In some cases you'd like to add Google Analytics to your page, but the `ga` variable is already being used for something else. To deal with this, you can rename the global ga object. +* `objectName` The name for the global (ga) object. Default is `ga`. * `anonymizeIp` Toggles if Google Analytics will anonymize the IP address for all hits. * `blockedIps` Here you can blacklist IP addresses. For those the Google Analytics script will not be embedded. + +* `cookieConfig`: Toggles if the a custom cookie configuration should be used. +* `cookieName` The cookie name. Default ist `_ga` +* `cookieDomain` The cookie domain. +* `cookieExpires` The cookie expiration time in seconds. Default is 2 years (`63072000` seconds) + * `debugStatus` Toggles if the debug version of Goggle Analytics is enabled or disabled. * `debugTrace` Toggles if the debugger will output more verbose information to the console. `debugStatus` must be enabled. diff --git a/blueprints.yaml b/blueprints.yaml index 35c067e..ffa8a2c 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,6 +1,6 @@ name: Google Analytics version: 1.4.0 -description: "The Google Analytics Plugin allows you to integrate and configure Google Analytics without the need to touch any code within your Grav site." +description: "Easily integrate and configure Google Analytics without the need to touch any code within your Grav site." icon: google author: name: John Linhart @@ -41,6 +41,11 @@ form: validate: required: true + Advanced: + type: section + title: PLUGIN_GANALYTICS.SECTION_ADVANCED + underline: true + position: type: toggle label: PLUGIN_GANALYTICS.POSITION @@ -53,17 +58,15 @@ form: validate: type: string - Advanced: - type: section - title: PLUGIN_GANALYTICS.SECTION_ADVANCED - underline: true + renameGa: # DEPRECATED + type: ignore - renameGa: + objectName: type: text - label: PLUGIN_GANALYTICS.RENAME_GA - help: PLUGIN_GANALYTICS.RENAME_GA_HELP + label: PLUGIN_GANALYTICS.OBJECT_NAME + help: PLUGIN_GANALYTICS.OBJECT_NAME_HELP size: small - placeholder: "ga" + default: "ga" async: type: toggle @@ -72,8 +75,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO validate: type: bool @@ -84,8 +87,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO validate: type: bool @@ -96,8 +99,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO validate: type: bool @@ -109,6 +112,47 @@ form: validate: type: commalist + Cookie: + type: section + title: PLUGIN_GANALYTICS.SECTION_COOKIE + underline: true + + cookieConfig: + type: toggle + label: PLUGIN_GANALYTICS.COOKIE_CONFIG + help: PLUGIN_GANALYTICS.COOKIE_CONFIG_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + cookieName: + type: text + label: PLUGIN_GANALYTICS.COOKIE_NAME + help: PLUGIN_GANALYTICS.COOKIE_NAME_HELP + size: small + default: "_ga" + + cookieDomain: + type: text + label: PLUGIN_GANALYTICS.COOKIE_DOMAIN + help: PLUGIN_GANALYTICS.COOKIE_DOMAIN_HELP + size: medium + + cookieExpires: + type: text + size: small + label: PLUGIN_GANALYTICS.COOKIE_EXPIRES + help: PLUGIN_GANALYTICS.COOKIE_EXPIRES_HELP + append: PLUGIN_GANALYTICS.SECONDS + default: 63072000 + validate: + type: number + min: 0 + Debug: type: section title: PLUGIN_GANALYTICS.SECTION_DEBUG @@ -121,8 +165,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO validate: type: bool @@ -133,7 +177,7 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO validate: type: bool \ No newline at end of file diff --git a/ganalytics.php b/ganalytics.php index 539e92b..26356b0 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -27,26 +27,46 @@ public static function getSubscribedEvents() ]; } + /** + * Returns the Google Analytics cookie configuration. + * @return string + */ + private function getCookieConfiguration(){ + $cookie_config = $this->config->get('plugins.ganalytics.cookieConfig', false); + if (!$cookie_config) return "'auto'"; + + $cookie_config = [ + 'cookieName' => $this->config->get('plugins.ganalytics.cookieName', '_ga'), + 'cookieExpires' => $this->config->get('plugins.ganalytics.cookieExpires', 63072000), + ]; + + // cookie domain + $cookie_domain = trim($this->config->get('plugins.ganalytics.cookieDomain')); + if (!empty($cookie_domain)) $cookie_config['cookieDomain'] = $cookie_domain; + + return json_encode($cookie_config); + } + /** * Return the Google Analytics Tracking Code * @param string $scriptName Name of the GA script library - * @param string $gaName Global variable name for the GA object + * @param string $objectName Global variable name for the GA object * @param bool $async Determine if the GA script should be loaded and executed asynchronously * @return string */ - private function getTrackingCode($scriptName, $gaName, $async=false) + private function getTrackingCode($scriptName, $objectName, $async=false) { if ($async) { $code = - "window.GoogleAnalyticsObject = '{$gaName}';\n". - "window.{$gaName}=window.{$gaName}||function(){({$gaName}.q={$gaName}.q||[]).push(arguments)};{$gaName}.l=+new Date;\n" + "window.GoogleAnalyticsObject = '{$objectName}';\n". + "window.{$objectName}=window.{$objectName}||function(){({$objectName}.q={$objectName}.q||[]).push(arguments)};{$objectName}.l=+new Date;\n" ; } else { $code = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n". "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n". "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n". - "})(window,document,'script','//www.google-analytics.com/{$scriptName}.js','{$gaName}');\n" + "})(window,document,'script','//www.google-analytics.com/{$scriptName}.js','{$objectName}');\n" ; } return $code; @@ -55,17 +75,19 @@ private function getTrackingCode($scriptName, $gaName, $async=false) /** * Return all personalized GA settings * @param string $trackingId Google Analytics Tracking ID - * @param string $gaName Global variable name for the GA object + * @param string $objectName Global variable name for the GA object * @return array */ - private function getTrackingSettings($trackingId, $gaName) + private function getTrackingSettings($trackingId, $objectName) { + $cookie_config = $this->getCookieConfiguration(); + $settings = [ 'trace-debug' => "window.ga_debug = {trace: true};", - 'create' => "{$gaName}('create', '{$trackingId}', 'auto');", - 'anonymize' => "{$gaName}('set', 'anonymizeIp', true);", - 'force-ssl' => "{$gaName}('set', 'forceSSL', true);", - 'send' => "{$gaName}('send', 'pageview');" + 'create' => "{$objectName}('create', '{$trackingId}', {$cookie_config});", + 'anonymize' => "{$objectName}('set', 'anonymizeIp', true);", + 'force-ssl' => "{$objectName}('set', 'forceSSL', true);", + 'send' => "{$objectName}('send', 'pageview');" ]; if (!$this->config->get('plugins.ganalytics.debugTrace', false)) unset ($settings['trace-debug']); @@ -75,11 +97,24 @@ private function getTrackingSettings($trackingId, $gaName) return $settings; } + /** + * Handle deprecated configuration options + */ + private function handleDeprecates(){ + $renameGa = trim($this->config->get('plugins.ganalytics.renameGa', '')); + if (!empty($renameGa)){ + $this->config->set('plugins.ganalytics.renameGa', ''); + $this->config->set('plugins.ganalytics.objectName', $renameGa); + } + } + /** * Add GA tracking JS when the assets are initialized */ public function onAssetsInitialized() { + $this->handleDeprecates(); + // Don't proceed if we are in the admin plugin if ($this->isAdmin()) return; @@ -89,7 +124,7 @@ public function onAssetsInitialized() $scriptName = $this->config->get('plugins.ganalytics.debugStatus', false) ? 'analytics_debug' : 'analytics'; $async = $this->config->get('plugins.ganalytics.async', false); $blockedIps = $this->config->get('plugins.ganalytics.blockedIps', []); - $gaName = trim($this->config->get('plugins.ganalytics.renameGa', '')); + $objectName = trim($this->config->get('plugins.ganalytics.objectName', 'ga')); // Don't proceed if there is no GA Tracking ID if (empty($trackingId)) return; @@ -97,12 +132,9 @@ public function onAssetsInitialized() // Don't proceed if the IP address is blocked if (in_array($_SERVER['REMOTE_ADDR'], $blockedIps)) return; - // Set the global (ga) variable name - if (empty($gaName)) $gaName = 'ga'; - // Tracking Code and settings - $settings = $this->getTrackingSettings($trackingId, $gaName); - $code = $this->getTrackingCode($scriptName, $gaName, $async); + $settings = $this->getTrackingSettings($trackingId, $objectName); + $code = $this->getTrackingCode($scriptName, $objectName, $async); $code.= join(PHP_EOL, $settings); // Embed Goggle Analytics script diff --git a/ganalytics.yaml b/ganalytics.yaml index 9db5b50..45ad6ce 100644 --- a/ganalytics.yaml +++ b/ganalytics.yaml @@ -1,10 +1,17 @@ enabled: true # Global enable/disable the entire plugin trackingId: "" # GA Tracking ID `REQUIRED` + position: "head" # Code Position in the HTML document -renameGa: "" # Other name for the global (ga) variable +objectName: "ga" # Name for the global (ga) object forceSsl: false # Enable/Disable SSL async: false # Enable/Disable Asynchronously Tracking anonymizeIp: false # Enable/Disable IP Anonymization blockedIps: [] # Array of blocked IP addresses + +cookieConfig: false # Use custom cookie configuration +cookieName: "_ga" # Cookie name +cookieDomain: "" # Cookie domain +cookieExpires: 63072000 # Expiration time in seconds (Default: 2 years) + debugStatus: false # Enable/disable Debugging debugTrace: false # Enable/Disable Trace Debugging \ No newline at end of file diff --git a/languages.yaml b/languages.yaml index 549b46d..ab76ae2 100644 --- a/languages.yaml +++ b/languages.yaml @@ -1,7 +1,9 @@ en: PLUGIN_GANALYTICS: + SECONDS: "seconds" SECTION_GENERAL: "General" SECTION_ADVANCED: "Advanced" + SECTION_COOKIE: "Cookie" SECTION_DEBUG: "Debug" TACKING_ID: "Tracking ID" TACKING_ID_HELP: "Google Analytics Tracking ID" @@ -15,36 +17,54 @@ en: FORCE_SSL_HELP: "Send all data using SSL, even from insecure (HTTP) pages" ANONYMIZE_IP: "IP Anonymization" ANONYMIZE_IP_HELP: "Enable the anonymization of the IP address" - RENAME_GA: "(ga) Variable" - RENAME_GA_HELP: "Rename the global (ga) variable of the Google Analytics object" + OBJECT_NAME: "(ga) Variable" + OBJECT_NAME_HELP: "Rename the global (ga) variable of the Google Analytics object" BLOCKED_IPS: "Blocked IP addresses" BLOCKED_IPS_HELP: "For the given IP addresses the Google Analytics code will not be embedded" + COOKIE_CONFIG: "Custom Configuration" + COOKIE_CONFIG_HELP: "Use a custom cookie configuration instead of the default one" + COOKIE_NAME: "Name" + COOKIE_NAME_HELP: "The Name of the Google Analytics cookie" + COOKIE_DOMAIN: "Domain" + COOKIE_DOMAIN_HELP: "The Cookie domain. Default is the hostname of the current URL" + COOKIE_EXPIRES: "Expires" + COOKIE_EXPIRES_HELP: "The expiration time of the Google Analytics cookie. Default is two years" DEBUG_STATUS: "Debug Version" - DEBUG_STATUS_HELP: "Enable the debug version of the analytics.js library" + DEBUG_STATUS_HELP: "Enable the debug version of the analyti cs.js library" DEBUG_TRACE: "Trace Debugging" DEBUG_TRACE_HELP: "Enabling trace debugging will output more verbose information to the console" de: PLUGIN_GANALYTICS: + SECONDS: "Sekunden" SECTION_GENERAL: "Allgemein" SECTION_ADVANCED: "Erweitert" + SECTION_COOKIE: "Cookie" SECTION_DEBUG: "Debugging" TACKING_ID: "Tracking-ID" TACKING_ID_HELP: "Google Analytics Tracking-ID" POSITION: "Code-Position" POSITION_HELP: "Position des Codes im HTML-Dokument (Head oder Body)" POSITION_HEAD: "Kopf" - POSITION_BODY: "Ende des Inhalts" + POSITION_BODY: "Inhaltsende" ASYNC: "Asynchron laden" ASYNC_HELP: "Erlaubt es modernen Browsern das Google Analytics Script im Voraus zu laden" FORCE_SSL: "SSL erzwingen" FORCE_SSL_HELP: "Alle Daten werden mit SSL gesendet, auch von unsicheren (HTTP) Seiten" ANONYMIZE_IP: "IP-Anonymisierung" ANONYMIZE_IP_HELP: "Aktiviert die Anonymisierung der IP-Adresse" - RENAME_GA: "(ga) Variable" - RENAME_GA_HELP: "Umbenennung der globalen (ga)-Variable für das Google Analytics Objekt" + OBJECT_NAME: "Globales (ga) Objekt" + OBJECT_NAME_HELP: "Variablenname des globalen Google Analytics Objekts (ga)" BLOCKED_IPS: "Gesperrte IP-Adressen" BLOCKED_IPS_HELP: "Für die angegebenen IP-Adressen wird der Google Analytics Code nicht eingebunden" + COOKIE_CONFIG: "Eigene Konfiguration" + COOKIE_CONFIG_HELP: "Soll eine eigene Cookie-Konfiguration oder die von Google Analytics genutzt werden" + COOKIE_NAME: "Name" + COOKIE_NAME_HELP: "Der Name des Google Analytics Cookie" + COOKIE_DOMAIN: "Domain" + COOKIE_DOMAIN_HELP: "Cookie Domain. Standardmäßig wird der Host-Name der aktuellen URL benutzt" + COOKIE_EXPIRES: "Läuft ab" + COOKIE_EXPIRES_HELP: "Die Ablaufzeit des Google Analytics Cookie. Standard sind zwei Jahre" DEBUG_STATUS: "Debug-Version" DEBUG_STATUS_HELP: "Aktiviert die Debugging-Version der analytics.js Bibliothek" DEBUG_TRACE: "Trace-Debugging" From 9153738863ba612d35f3ab415c061e6ee4b93a9b Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Fri, 23 Dec 2016 16:04:31 +0100 Subject: [PATCH 09/17] Because there are so many translations... use separate files --- languages.yaml | 71 ----------------------------------------------- languages/de.yaml | 34 +++++++++++++++++++++++ languages/en.yaml | 34 +++++++++++++++++++++++ 3 files changed, 68 insertions(+), 71 deletions(-) delete mode 100644 languages.yaml create mode 100644 languages/de.yaml create mode 100644 languages/en.yaml diff --git a/languages.yaml b/languages.yaml deleted file mode 100644 index ab76ae2..0000000 --- a/languages.yaml +++ /dev/null @@ -1,71 +0,0 @@ -en: - PLUGIN_GANALYTICS: - SECONDS: "seconds" - SECTION_GENERAL: "General" - SECTION_ADVANCED: "Advanced" - SECTION_COOKIE: "Cookie" - SECTION_DEBUG: "Debug" - TACKING_ID: "Tracking ID" - TACKING_ID_HELP: "Google Analytics Tracking ID" - POSITION: "Code Position" - POSITION_HELP: "Code Position in the HTML document (head or body)" - POSITION_HEAD: "Head" - POSITION_BODY: "End of Body" - ASYNC: "Load asynchronously" - ASYNC_HELP: "Allow modern browsers to preload the Google Analytics script" - FORCE_SSL: "Force SSL" - FORCE_SSL_HELP: "Send all data using SSL, even from insecure (HTTP) pages" - ANONYMIZE_IP: "IP Anonymization" - ANONYMIZE_IP_HELP: "Enable the anonymization of the IP address" - OBJECT_NAME: "(ga) Variable" - OBJECT_NAME_HELP: "Rename the global (ga) variable of the Google Analytics object" - BLOCKED_IPS: "Blocked IP addresses" - BLOCKED_IPS_HELP: "For the given IP addresses the Google Analytics code will not be embedded" - COOKIE_CONFIG: "Custom Configuration" - COOKIE_CONFIG_HELP: "Use a custom cookie configuration instead of the default one" - COOKIE_NAME: "Name" - COOKIE_NAME_HELP: "The Name of the Google Analytics cookie" - COOKIE_DOMAIN: "Domain" - COOKIE_DOMAIN_HELP: "The Cookie domain. Default is the hostname of the current URL" - COOKIE_EXPIRES: "Expires" - COOKIE_EXPIRES_HELP: "The expiration time of the Google Analytics cookie. Default is two years" - DEBUG_STATUS: "Debug Version" - DEBUG_STATUS_HELP: "Enable the debug version of the analyti cs.js library" - DEBUG_TRACE: "Trace Debugging" - DEBUG_TRACE_HELP: "Enabling trace debugging will output more verbose information to the console" - -de: - PLUGIN_GANALYTICS: - SECONDS: "Sekunden" - SECTION_GENERAL: "Allgemein" - SECTION_ADVANCED: "Erweitert" - SECTION_COOKIE: "Cookie" - SECTION_DEBUG: "Debugging" - TACKING_ID: "Tracking-ID" - TACKING_ID_HELP: "Google Analytics Tracking-ID" - POSITION: "Code-Position" - POSITION_HELP: "Position des Codes im HTML-Dokument (Head oder Body)" - POSITION_HEAD: "Kopf" - POSITION_BODY: "Inhaltsende" - ASYNC: "Asynchron laden" - ASYNC_HELP: "Erlaubt es modernen Browsern das Google Analytics Script im Voraus zu laden" - FORCE_SSL: "SSL erzwingen" - FORCE_SSL_HELP: "Alle Daten werden mit SSL gesendet, auch von unsicheren (HTTP) Seiten" - ANONYMIZE_IP: "IP-Anonymisierung" - ANONYMIZE_IP_HELP: "Aktiviert die Anonymisierung der IP-Adresse" - OBJECT_NAME: "Globales (ga) Objekt" - OBJECT_NAME_HELP: "Variablenname des globalen Google Analytics Objekts (ga)" - BLOCKED_IPS: "Gesperrte IP-Adressen" - BLOCKED_IPS_HELP: "Für die angegebenen IP-Adressen wird der Google Analytics Code nicht eingebunden" - COOKIE_CONFIG: "Eigene Konfiguration" - COOKIE_CONFIG_HELP: "Soll eine eigene Cookie-Konfiguration oder die von Google Analytics genutzt werden" - COOKIE_NAME: "Name" - COOKIE_NAME_HELP: "Der Name des Google Analytics Cookie" - COOKIE_DOMAIN: "Domain" - COOKIE_DOMAIN_HELP: "Cookie Domain. Standardmäßig wird der Host-Name der aktuellen URL benutzt" - COOKIE_EXPIRES: "Läuft ab" - COOKIE_EXPIRES_HELP: "Die Ablaufzeit des Google Analytics Cookie. Standard sind zwei Jahre" - DEBUG_STATUS: "Debug-Version" - DEBUG_STATUS_HELP: "Aktiviert die Debugging-Version der analytics.js Bibliothek" - DEBUG_TRACE: "Trace-Debugging" - DEBUG_TRACE_HELP: "Ausführlichere Informationen werden auf der Konsole ausgegeben" \ No newline at end of file diff --git a/languages/de.yaml b/languages/de.yaml new file mode 100644 index 0000000..d4d7c2f --- /dev/null +++ b/languages/de.yaml @@ -0,0 +1,34 @@ +PLUGIN_GANALYTICS: + SECONDS: "Sekunden" + SECTION_GENERAL: "Allgemein" + SECTION_ADVANCED: "Erweitert" + SECTION_COOKIE: "Cookie" + SECTION_DEBUG: "Debugging" + TACKING_ID: "Tracking-ID" + TACKING_ID_HELP: "Google Analytics Tracking-ID" + POSITION: "Code-Position" + POSITION_HELP: "Position des Codes im HTML-Dokument (Head oder Body)" + POSITION_HEAD: "Kopf" + POSITION_BODY: "Inhaltsende" + ASYNC: "Asynchron laden" + ASYNC_HELP: "Erlaubt es modernen Browsern das Google Analytics Script im Voraus zu laden" + FORCE_SSL: "SSL erzwingen" + FORCE_SSL_HELP: "Alle Daten werden mit SSL gesendet, auch von unsicheren (HTTP) Seiten" + ANONYMIZE_IP: "IP-Anonymisierung" + ANONYMIZE_IP_HELP: "Aktiviert die Anonymisierung der IP-Adresse" + OBJECT_NAME: "Globales (ga) Objekt" + OBJECT_NAME_HELP: "Variablenname des globalen Google Analytics Objekts (ga)" + BLOCKED_IPS: "Gesperrte IP-Adressen" + BLOCKED_IPS_HELP: "Für die angegebenen IP-Adressen wird der Google Analytics Code nicht eingebunden" + COOKIE_CONFIG: "Eigene Konfiguration" + COOKIE_CONFIG_HELP: "Soll eine eigene Cookie-Konfiguration oder die von Google Analytics genutzt werden" + COOKIE_NAME: "Name" + COOKIE_NAME_HELP: "Der Name des Google Analytics Cookie" + COOKIE_DOMAIN: "Domain" + COOKIE_DOMAIN_HELP: "Cookie Domain. Standardmäßig wird der Host-Name der aktuellen URL benutzt" + COOKIE_EXPIRES: "Läuft ab" + COOKIE_EXPIRES_HELP: "Die Ablaufzeit des Google Analytics Cookie. Standard sind zwei Jahre" + DEBUG_STATUS: "Debug-Version" + DEBUG_STATUS_HELP: "Aktiviert die Debugging-Version der analytics.js Bibliothek" + DEBUG_TRACE: "Trace-Debugging" + DEBUG_TRACE_HELP: "Ausführlichere Informationen werden auf der Konsole ausgegeben" \ No newline at end of file diff --git a/languages/en.yaml b/languages/en.yaml new file mode 100644 index 0000000..c237157 --- /dev/null +++ b/languages/en.yaml @@ -0,0 +1,34 @@ +PLUGIN_GANALYTICS: + SECONDS: "seconds" + SECTION_GENERAL: "General" + SECTION_ADVANCED: "Advanced" + SECTION_COOKIE: "Cookie" + SECTION_DEBUG: "Debug" + TACKING_ID: "Tracking ID" + TACKING_ID_HELP: "Google Analytics Tracking ID" + POSITION: "Code Position" + POSITION_HELP: "Code Position in the HTML document (head or body)" + POSITION_HEAD: "Head" + POSITION_BODY: "End of Body" + ASYNC: "Load asynchronously" + ASYNC_HELP: "Allow modern browsers to preload the Google Analytics script" + FORCE_SSL: "Force SSL" + FORCE_SSL_HELP: "Send all data using SSL, even from insecure (HTTP) pages" + ANONYMIZE_IP: "IP Anonymization" + ANONYMIZE_IP_HELP: "Enable the anonymization of the IP address" + OBJECT_NAME: "Global (ga) Object" + OBJECT_NAME_HELP: "Rename the global (ga) variable of the Google Analytics object" + BLOCKED_IPS: "Blocked IP addresses" + BLOCKED_IPS_HELP: "For the given IP addresses the Google Analytics code will not be embedded" + COOKIE_CONFIG: "Custom Configuration" + COOKIE_CONFIG_HELP: "Use a custom cookie configuration instead of the default one" + COOKIE_NAME: "Name" + COOKIE_NAME_HELP: "The Name of the Google Analytics cookie" + COOKIE_DOMAIN: "Domain" + COOKIE_DOMAIN_HELP: "The Cookie domain. Default is the hostname of the current URL" + COOKIE_EXPIRES: "Expires" + COOKIE_EXPIRES_HELP: "The expiration time of the Google Analytics cookie. Default is two years" + DEBUG_STATUS: "Debug Version" + DEBUG_STATUS_HELP: "Enable the debug version of the analyti cs.js library" + DEBUG_TRACE: "Trace Debugging" + DEBUG_TRACE_HELP: "Enabling trace debugging will output more verbose information to the console" \ No newline at end of file From c7966359bfcdf10a9e324ab78856969c7fe584be Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Fri, 23 Dec 2016 16:26:52 +0100 Subject: [PATCH 10/17] Use Tabs for plugin configuration --- CHANGELOG.md | 3 +- LICENSE | 2 +- blueprints.yaml | 331 ++++++++++++++++++++++++------------------------ 3 files changed, 169 insertions(+), 167 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6478e0b..919bd44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ * Custom Cookie Configuration. Name, domain and expiration time are configurable. * Force SSL - Send all data using SSL, even from insecure (HTTP) pages 1. [](#improved) - * Better use and configuration of the global object name. Please don't use `renameGa` anymore. + * Improve plugin configuration with tab views. + * Better use and configuration of the global object name. Please use `objectName` instead of `renameGa`. # v1.3.0 ## 12/21/2016 diff --git a/LICENSE b/LICENSE index 0b67f50..0ac012c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 John Linhart +Copyright (c) 2016 John Linhart (admin@escope.cz), Christian Worreschk (cw@marsec.de) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/blueprints.yaml b/blueprints.yaml index ffa8a2c..580d9bd 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -16,168 +16,169 @@ form: validation: strict fields: - Basics: - type: section - title: PLUGIN_GANALYTICS.SECTION_GENERAL - underline: false - - enabled: - type: toggle - label: PLUGIN_ADMIN.PLUGIN_STATUS - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool - - trackingId: - type: text - size: medium - label: PLUGIN_GANALYTICS.TACKING_ID - help: PLUGIN_GANALYTICS.TACKING_ID_HELP - placeholder: "UA-00000000-0" - validate: - required: true - - Advanced: - type: section - title: PLUGIN_GANALYTICS.SECTION_ADVANCED - underline: true - - position: - type: toggle - label: PLUGIN_GANALYTICS.POSITION - help: PLUGIN_GANALYTICS.POSITION_HELP - hightlight: 1 - default: head - options: - head: PLUGIN_GANALYTICS.POSITION_HEAD - body: PLUGIN_GANALYTICS.POSITION_BODY - validate: - type: string - - renameGa: # DEPRECATED - type: ignore - - objectName: - type: text - label: PLUGIN_GANALYTICS.OBJECT_NAME - help: PLUGIN_GANALYTICS.OBJECT_NAME_HELP - size: small - default: "ga" - - async: - type: toggle - label: PLUGIN_GANALYTICS.ASYNC - help: PLUGIN_GANALYTICS.ASYNC_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - forceSsl: - type: toggle - label: PLUGIN_GANALYTICS.FORCE_SSL - help: PLUGIN_GANALYTICS.FORCE_SSL_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - anonymizeIp: - type: toggle - label: PLUGIN_GANALYTICS.ANONYMIZE_IP - help: PLUGIN_GANALYTICS.ANONYMIZE_IP_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - blockedIps: - type: selectize - size: large - label: PLUGIN_GANALYTICS.BLOCKED_IPS - help: PLUGIN_GANALYTICS.BLOCKED_IPS_HELP - validate: - type: commalist - - Cookie: - type: section - title: PLUGIN_GANALYTICS.SECTION_COOKIE - underline: true - - cookieConfig: - type: toggle - label: PLUGIN_GANALYTICS.COOKIE_CONFIG - help: PLUGIN_GANALYTICS.COOKIE_CONFIG_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - cookieName: - type: text - label: PLUGIN_GANALYTICS.COOKIE_NAME - help: PLUGIN_GANALYTICS.COOKIE_NAME_HELP - size: small - default: "_ga" - - cookieDomain: - type: text - label: PLUGIN_GANALYTICS.COOKIE_DOMAIN - help: PLUGIN_GANALYTICS.COOKIE_DOMAIN_HELP - size: medium - - cookieExpires: - type: text - size: small - label: PLUGIN_GANALYTICS.COOKIE_EXPIRES - help: PLUGIN_GANALYTICS.COOKIE_EXPIRES_HELP - append: PLUGIN_GANALYTICS.SECONDS - default: 63072000 - validate: - type: number - min: 0 - - Debug: - type: section - title: PLUGIN_GANALYTICS.SECTION_DEBUG - underline: true - - debugStatus: - type: toggle - label: PLUGIN_GANALYTICS.DEBUG_STATUS - help: PLUGIN_GANALYTICS.DEBUG_STATUS_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - debugTrace: - type: toggle - label: PLUGIN_GANALYTICS.DEBUG_TRACE - help: PLUGIN_GANALYTICS.DEBUG_TRACE_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool \ No newline at end of file + tabs: + type: tabs + active: 1 + + fields: + + general: + type: tab + title: PLUGIN_GANALYTICS.SECTION_GENERAL + fields: + enabled: + type: toggle + label: PLUGIN_ADMIN.PLUGIN_STATUS + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + trackingId: + type: text + size: medium + label: PLUGIN_GANALYTICS.TACKING_ID + help: PLUGIN_GANALYTICS.TACKING_ID_HELP + placeholder: "UA-00000000-0" + validate: + required: true + + advanced: + type: tab + title: PLUGIN_GANALYTICS.SECTION_ADVANCED + fields: + position: + type: toggle + label: PLUGIN_GANALYTICS.POSITION + help: PLUGIN_GANALYTICS.POSITION_HELP + hightlight: 1 + default: head + options: + head: PLUGIN_GANALYTICS.POSITION_HEAD + body: PLUGIN_GANALYTICS.POSITION_BODY + validate: + type: string + + renameGa: # DEPRECATED + type: ignore + + objectName: + type: text + label: PLUGIN_GANALYTICS.OBJECT_NAME + help: PLUGIN_GANALYTICS.OBJECT_NAME_HELP + size: small + default: "ga" + + async: + type: toggle + label: PLUGIN_GANALYTICS.ASYNC + help: PLUGIN_GANALYTICS.ASYNC_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + forceSsl: + type: toggle + label: PLUGIN_GANALYTICS.FORCE_SSL + help: PLUGIN_GANALYTICS.FORCE_SSL_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + anonymizeIp: + type: toggle + label: PLUGIN_GANALYTICS.ANONYMIZE_IP + help: PLUGIN_GANALYTICS.ANONYMIZE_IP_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + blockedIps: + type: array + size: large + label: PLUGIN_GANALYTICS.BLOCKED_IPS + help: PLUGIN_GANALYTICS.BLOCKED_IPS_HELP + value_only: true + + cookie: + type: tab + title: PLUGIN_GANALYTICS.SECTION_COOKIE + fields: + cookieConfig: + type: toggle + label: PLUGIN_GANALYTICS.COOKIE_CONFIG + help: PLUGIN_GANALYTICS.COOKIE_CONFIG_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + cookieName: + type: text + label: PLUGIN_GANALYTICS.COOKIE_NAME + help: PLUGIN_GANALYTICS.COOKIE_NAME_HELP + size: small + default: "_ga" + + cookieDomain: + type: text + label: PLUGIN_GANALYTICS.COOKIE_DOMAIN + help: PLUGIN_GANALYTICS.COOKIE_DOMAIN_HELP + size: medium + + cookieExpires: + type: text + size: small + label: PLUGIN_GANALYTICS.COOKIE_EXPIRES + help: PLUGIN_GANALYTICS.COOKIE_EXPIRES_HELP + append: PLUGIN_GANALYTICS.SECONDS + default: 63072000 + validate: + type: number + min: 0 + + debug: + type: tab + title: PLUGIN_GANALYTICS.SECTION_DEBUG + fields: + debugStatus: + type: toggle + label: PLUGIN_GANALYTICS.DEBUG_STATUS + help: PLUGIN_GANALYTICS.DEBUG_STATUS_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + debugTrace: + type: toggle + label: PLUGIN_GANALYTICS.DEBUG_TRACE + help: PLUGIN_GANALYTICS.DEBUG_TRACE_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool \ No newline at end of file From d58851e4ef5075500169291a5bd2c3d5d4477075 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Mon, 2 Jan 2017 09:47:48 +0100 Subject: [PATCH 11/17] Typo --- README.md | 4 ++-- ganalytics.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 30f4855..c864dee 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,9 @@ debugTrace: false * `cookieConfig`: Toggles if the a custom cookie configuration should be used. * `cookieName` The cookie name. Default ist `_ga` * `cookieDomain` The cookie domain. -* `cookieExpires` The cookie expiration time in seconds. Default is 2 years (`63072000` seconds) +* `cookieExpires` The cookie expiration time in seconds. Google default is 2 years (`63072000` seconds) -* `debugStatus` Toggles if the debug version of Goggle Analytics is enabled or disabled. +* `debugStatus` Toggles if the debug version of Google Analytics is enabled or disabled. * `debugTrace` Toggles if the debugger will output more verbose information to the console. `debugStatus` must be enabled. ## Usage diff --git a/ganalytics.php b/ganalytics.php index 26356b0..6010671 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -137,7 +137,7 @@ public function onAssetsInitialized() $code = $this->getTrackingCode($scriptName, $objectName, $async); $code.= join(PHP_EOL, $settings); - // Embed Goggle Analytics script + // Embed Google Analytics script $group = ($position == 'body') ? 'bottom' : null; $this->grav['assets']->addInlineJs($code, null, $group); From 71db0491a442fcfd930e781ecf536b13dfbd4d88 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Mon, 2 Jan 2017 10:23:59 +0100 Subject: [PATCH 12/17] Use the same configuration layout like the login plugin --- blueprints.yaml | 144 ++++++++++++++++++++++++---------------------- languages/de.yaml | 2 +- languages/en.yaml | 2 +- 3 files changed, 76 insertions(+), 72 deletions(-) diff --git a/blueprints.yaml b/blueprints.yaml index 580d9bd..61c49dd 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -19,13 +19,15 @@ form: tabs: type: tabs active: 1 + class: subtle fields: - general: + configuration: type: tab - title: PLUGIN_GANALYTICS.SECTION_GENERAL + title: PLUGIN_GANALYTICS.SECTION_CONFIGURATIONS fields: + enabled: type: toggle label: PLUGIN_ADMIN.PLUGIN_STATUS @@ -46,74 +48,76 @@ form: validate: required: true - advanced: - type: tab - title: PLUGIN_GANALYTICS.SECTION_ADVANCED - fields: - position: - type: toggle - label: PLUGIN_GANALYTICS.POSITION - help: PLUGIN_GANALYTICS.POSITION_HELP - hightlight: 1 - default: head - options: - head: PLUGIN_GANALYTICS.POSITION_HEAD - body: PLUGIN_GANALYTICS.POSITION_BODY - validate: - type: string - - renameGa: # DEPRECATED - type: ignore - - objectName: - type: text - label: PLUGIN_GANALYTICS.OBJECT_NAME - help: PLUGIN_GANALYTICS.OBJECT_NAME_HELP - size: small - default: "ga" - - async: - type: toggle - label: PLUGIN_GANALYTICS.ASYNC - help: PLUGIN_GANALYTICS.ASYNC_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - forceSsl: - type: toggle - label: PLUGIN_GANALYTICS.FORCE_SSL - help: PLUGIN_GANALYTICS.FORCE_SSL_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - anonymizeIp: - type: toggle - label: PLUGIN_GANALYTICS.ANONYMIZE_IP - help: PLUGIN_GANALYTICS.ANONYMIZE_IP_HELP - hightlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO - validate: - type: bool - - blockedIps: - type: array - size: large - label: PLUGIN_GANALYTICS.BLOCKED_IPS - help: PLUGIN_GANALYTICS.BLOCKED_IPS_HELP - value_only: true + advanced: + type: section + title: PLUGIN_GANALYTICS.SECTION_ADVANCED + underline: true + fields: + + position: + type: toggle + label: PLUGIN_GANALYTICS.POSITION + help: PLUGIN_GANALYTICS.POSITION_HELP + hightlight: 1 + default: head + options: + head: PLUGIN_GANALYTICS.POSITION_HEAD + body: PLUGIN_GANALYTICS.POSITION_BODY + validate: + type: string + + renameGa: # DEPRECATED + type: ignore + + objectName: + type: text + label: PLUGIN_GANALYTICS.OBJECT_NAME + help: PLUGIN_GANALYTICS.OBJECT_NAME_HELP + size: small + default: "ga" + + async: + type: toggle + label: PLUGIN_GANALYTICS.ASYNC + help: PLUGIN_GANALYTICS.ASYNC_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + forceSsl: + type: toggle + label: PLUGIN_GANALYTICS.FORCE_SSL + help: PLUGIN_GANALYTICS.FORCE_SSL_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + anonymizeIp: + type: toggle + label: PLUGIN_GANALYTICS.ANONYMIZE_IP + help: PLUGIN_GANALYTICS.ANONYMIZE_IP_HELP + hightlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + blockedIps: + type: array + size: large + label: PLUGIN_GANALYTICS.BLOCKED_IPS + help: PLUGIN_GANALYTICS.BLOCKED_IPS_HELP + value_only: true cookie: type: tab diff --git a/languages/de.yaml b/languages/de.yaml index d4d7c2f..ec08849 100644 --- a/languages/de.yaml +++ b/languages/de.yaml @@ -1,6 +1,6 @@ PLUGIN_GANALYTICS: SECONDS: "Sekunden" - SECTION_GENERAL: "Allgemein" + SECTION_CONFIGURATIONS: "Einstellungen" SECTION_ADVANCED: "Erweitert" SECTION_COOKIE: "Cookie" SECTION_DEBUG: "Debugging" diff --git a/languages/en.yaml b/languages/en.yaml index c237157..190c032 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -1,6 +1,6 @@ PLUGIN_GANALYTICS: SECONDS: "seconds" - SECTION_GENERAL: "General" + SECTION_CONFIGURATIONS: "Configurations" SECTION_ADVANCED: "Advanced" SECTION_COOKIE: "Cookie" SECTION_DEBUG: "Debug" From da94b8d6ba30c6f4f778943895df44079a53a5de Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Mon, 2 Jan 2017 10:24:51 +0100 Subject: [PATCH 13/17] Handle the deprecated stuff in onPluginInitialized() --- ganalytics.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ganalytics.php b/ganalytics.php index 6010671..68b8cae 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -23,6 +23,7 @@ class GanalyticsPlugin extends Plugin public static function getSubscribedEvents() { return [ + 'onPluginsInitialized' => ['onPluginsInitialized', 0], 'onAssetsInitialized' => ['onAssetsInitialized', 0] ]; } @@ -97,10 +98,9 @@ private function getTrackingSettings($trackingId, $objectName) return $settings; } - /** - * Handle deprecated configuration options - */ - private function handleDeprecates(){ + // Handle deprecated stuff when the plugin is initialized + public function onPluginsInitialized() + { $renameGa = trim($this->config->get('plugins.ganalytics.renameGa', '')); if (!empty($renameGa)){ $this->config->set('plugins.ganalytics.renameGa', ''); @@ -113,8 +113,6 @@ private function handleDeprecates(){ */ public function onAssetsInitialized() { - $this->handleDeprecates(); - // Don't proceed if we are in the admin plugin if ($this->isAdmin()) return; From 6797252d8393d028c85f93d8b3113a5da4473228 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Mon, 2 Jan 2017 12:56:54 +0100 Subject: [PATCH 14/17] Renaming + Typo fix --- blueprints.yaml | 5 +---- languages/de.yaml | 2 +- languages/en.yaml | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/blueprints.yaml b/blueprints.yaml index 61c49dd..fab8363 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -25,7 +25,7 @@ form: configuration: type: tab - title: PLUGIN_GANALYTICS.SECTION_CONFIGURATIONS + title: PLUGIN_GANALYTICS.SECTION_CONFIGURATION fields: enabled: @@ -66,9 +66,6 @@ form: validate: type: string - renameGa: # DEPRECATED - type: ignore - objectName: type: text label: PLUGIN_GANALYTICS.OBJECT_NAME diff --git a/languages/de.yaml b/languages/de.yaml index ec08849..c80d17d 100644 --- a/languages/de.yaml +++ b/languages/de.yaml @@ -1,6 +1,6 @@ PLUGIN_GANALYTICS: SECONDS: "Sekunden" - SECTION_CONFIGURATIONS: "Einstellungen" + SECTION_CONFIGURATION: "Einstellungen" SECTION_ADVANCED: "Erweitert" SECTION_COOKIE: "Cookie" SECTION_DEBUG: "Debugging" diff --git a/languages/en.yaml b/languages/en.yaml index 190c032..cf17c3e 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -1,6 +1,6 @@ PLUGIN_GANALYTICS: SECONDS: "seconds" - SECTION_CONFIGURATIONS: "Configurations" + SECTION_CONFIGURATION: "Configuration" SECTION_ADVANCED: "Advanced" SECTION_COOKIE: "Cookie" SECTION_DEBUG: "Debug" @@ -29,6 +29,6 @@ PLUGIN_GANALYTICS: COOKIE_EXPIRES: "Expires" COOKIE_EXPIRES_HELP: "The expiration time of the Google Analytics cookie. Default is two years" DEBUG_STATUS: "Debug Version" - DEBUG_STATUS_HELP: "Enable the debug version of the analyti cs.js library" + DEBUG_STATUS_HELP: "Enable the debug version of the analytics.js library" DEBUG_TRACE: "Trace Debugging" DEBUG_TRACE_HELP: "Enabling trace debugging will output more verbose information to the console" \ No newline at end of file From 11deca494f670e45a713d0c3fc4499908529d6f5 Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Mon, 2 Jan 2017 12:59:43 +0100 Subject: [PATCH 15/17] Save configuration after fixing deprecated settings --- ganalytics.php | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/ganalytics.php b/ganalytics.php index 68b8cae..f529477 100644 --- a/ganalytics.php +++ b/ganalytics.php @@ -98,16 +98,29 @@ private function getTrackingSettings($trackingId, $objectName) return $settings; } - // Handle deprecated stuff when the plugin is initialized - public function onPluginsInitialized() + /** + * Do something with deprecated settings + */ + private function processDeprecatedSettings() { + // 1.3.0 => 1.4.0 + // Field: "renameGa" => "objectName" $renameGa = trim($this->config->get('plugins.ganalytics.renameGa', '')); - if (!empty($renameGa)){ - $this->config->set('plugins.ganalytics.renameGa', ''); - $this->config->set('plugins.ganalytics.objectName', $renameGa); + if (!empty($renameGa)) { + $settings = $this->config->get('plugins.ganalytics', []); + $settings['objectName'] = $renameGa; + unset($settings['renameGa']); + $this->config->set('plugins.ganalytics', $settings); + Plugin::saveConfig('ganalytics'); } } + // Handle deprecated stuff when the plugin is initialized + public function onPluginsInitialized() + { + $this->processDeprecatedSettings(); + } + /** * Add GA tracking JS when the assets are initialized */ @@ -116,20 +129,20 @@ public function onAssetsInitialized() // Don't proceed if we are in the admin plugin if ($this->isAdmin()) return; - // Parameters - $trackingId = trim($this->config->get('plugins.ganalytics.trackingId', '')); - $position = trim($this->config->get('plugins.ganalytics.position', 'head')); - $scriptName = $this->config->get('plugins.ganalytics.debugStatus', false) ? 'analytics_debug' : 'analytics'; - $async = $this->config->get('plugins.ganalytics.async', false); - $blockedIps = $this->config->get('plugins.ganalytics.blockedIps', []); - $objectName = trim($this->config->get('plugins.ganalytics.objectName', 'ga')); - // Don't proceed if there is no GA Tracking ID + $trackingId = trim($this->config->get('plugins.ganalytics.trackingId', '')); if (empty($trackingId)) return; // Don't proceed if the IP address is blocked + $blockedIps = $this->config->get('plugins.ganalytics.blockedIps', []); if (in_array($_SERVER['REMOTE_ADDR'], $blockedIps)) return; + // Parameters + $scriptName = $this->config->get('plugins.ganalytics.debugStatus', false) ? 'analytics_debug' : 'analytics'; + $objectName = trim($this->config->get('plugins.ganalytics.objectName', 'ga')); + $async = $this->config->get('plugins.ganalytics.async', false); + $position = trim($this->config->get('plugins.ganalytics.position', 'head')); + // Tracking Code and settings $settings = $this->getTrackingSettings($trackingId, $objectName); $code = $this->getTrackingCode($scriptName, $objectName, $async); From 5bcabeb724c6a5bf86e1b37456fbc1e9b3d626a9 Mon Sep 17 00:00:00 2001 From: cworreschk Date: Wed, 4 Jan 2017 09:22:24 +0100 Subject: [PATCH 16/17] Remove dependency of the admin plugin --- blueprints.yaml | 30 +++++++++++++++--------------- languages/de.yaml | 5 +++++ languages/en.yaml | 5 +++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/blueprints.yaml b/blueprints.yaml index fab8363..717dc74 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -30,12 +30,12 @@ form: enabled: type: toggle - label: PLUGIN_ADMIN.PLUGIN_STATUS + label: PLUGIN_GANALYTICS.PLUGIN_STATUS hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED + 1: PLUGIN_GANALYTICS.ENABLED + 0: PLUGIN_GANALYTICS.DISABLED validate: type: bool @@ -80,8 +80,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO + 1: PLUGIN_GANALYTICS._YES + 0: PLUGIN_GANALYTICS._NO validate: type: bool @@ -92,8 +92,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO + 1: PLUGIN_GANALYTICS._YES + 0: PLUGIN_GANALYTICS._NO validate: type: bool @@ -104,8 +104,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO + 1: PLUGIN_GANALYTICS._YES + 0: PLUGIN_GANALYTICS._NO validate: type: bool @@ -127,8 +127,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO + 1: PLUGIN_GANALYTICS._YES + 0: PLUGIN_GANALYTICS._NO validate: type: bool @@ -167,8 +167,8 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO + 1: PLUGIN_GANALYTICS.ENABLED + 0: PLUGIN_GANALYTICS.DISABLED validate: type: bool @@ -179,7 +179,7 @@ form: hightlight: 1 default: 0 options: - 1: PLUGIN_ADMIN.YES - 0: PLUGIN_ADMIN.NO + 1: PLUGIN_GANALYTICS.ENABLED + 0: PLUGIN_GANALYTICS.DISABLED validate: type: bool \ No newline at end of file diff --git a/languages/de.yaml b/languages/de.yaml index c80d17d..3eda61d 100644 --- a/languages/de.yaml +++ b/languages/de.yaml @@ -1,4 +1,9 @@ PLUGIN_GANALYTICS: + _YES: "Ja" #BUG: Only "YES" or "NO" will not work! + _NO: "Nein" #BUG: Only "YES" or "NO" will not work! + ENABLED: "Aktiviert" + DISABLED: "Deaktiviert" + PLUGIN_STATUS: "Plugin Status" SECONDS: "Sekunden" SECTION_CONFIGURATION: "Einstellungen" SECTION_ADVANCED: "Erweitert" diff --git a/languages/en.yaml b/languages/en.yaml index cf17c3e..ae8ad9f 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -1,4 +1,9 @@ PLUGIN_GANALYTICS: + _YES: "Yes" #BUG: Only "YES" or "NO" will not work! + _NO: "No" #BUG: Only "YES" or "NO" will not work! + ENABLED: "Enabled" + DISABLED: "Disabled" + PLUGIN_STATUS: "Plugin status" SECONDS: "seconds" SECTION_CONFIGURATION: "Configuration" SECTION_ADVANCED: "Advanced" From 964bd5f405cc89e67bbbe8d8618225378c21bda7 Mon Sep 17 00:00:00 2001 From: cworreschk Date: Wed, 4 Jan 2017 09:24:53 +0100 Subject: [PATCH 17/17] Add the current date of version 1.4 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 919bd44..231ce9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v1.4.0 -## 12/xx/2016 +## 01/04/2017 1. [](#new) * Preload the Google Analytics script asynchronously